Analysis of sin, cos and Tan calculation of calculator in Android Development
This paper describes the calculation of sin, cos and Tan values of calculators in Android development. Share with you for your reference, as follows:
Received a demand: ask the calculator sin90 = 1. I know it's very doubtful. Isn't it equal to one? Four or five mobile phones were tested, some satisfied, some sin90 = 0.8939. After checking the API documents, it is found that math. Sin / CoS / tan() in JDK is evaluated in radians. At present, most mobile calculators will not meet sin (PI / 2) = 1 if sin (90) = 1, because their algorithm converts radians (x / 180 * PI). When entering radians, it will change to sin (radians / 180 * PI) and make the result wrong. The implementation of calculator algorithm makes it possible to separate whether sin contains PI for different processing
My solution is as follows:
Modify the code via \ packages \ apps \ calculator \ SRC \ com \ Android \ calculator \ calculatorexpressionevaluator.java
Partial source code:
The input formula is passed in through this method, and then the calculated value is obtained by turning to another class, which is located at org. Javia. Arity. Symbols; (it cannot be opened when it is encapsulated, and only the substitution value can be modified)
My solution is:
Break whether the string contains "sin (", "cos (", "Tan (") characters and does not contain "sin (PI)", "cos (PI)", "Tan (PI)". If so, add the string "pi / 180 *" after each character
So I added a regular expression filter before substitution
Then you can satisfy sin90 = 1!
PS: Here we recommend several calculation tools for your further reference:
Online univariate function (equation) solving calculation tool: http://tools.jb51.net/jisuanqi/equ_ jisuanqi
Scientific calculator Online_ Advanced calculator online computing: http://tools.jb51.net/jisuanqi/jsqkexue
Online calculator_ Standard calculator: http://tools.jb51.net/jisuanqi/jsq
More readers interested in Android related content can view the special topics of this site: introduction and advanced tutorial of Android development, summary of Android basic component usage, summary of Android view skills, summary of Android layout skills and summary of Android control usage
I hope this article will help you in Android programming.