1

I'm working on a simple calculator application. But the trigonometric functions in dart when working with the machine-pi values give values, such as, tan90 gives 16331239353195370.0 and cos90 gives 6.123233995736766e-17.

I am simply converting degrees to radians using angle_in_degree * (math.pi / 180) for feeding the dart trigonometric functions.

I want to somehow approximate (or round off) these values, such that the output is similar to: 0 for cos90, infinite for tan90, etc. How can I efficiently and accurately do this?

Shourya Shikhar
  • 1,342
  • 1
  • 11
  • 29
  • 2
    I doubt that you will be satisfied with floating-point arithmetic, which [inherently cannot exactly represent fractional decimal numbers](https://stackoverflow.com/q/588004/). You might prefer using [`package:decimal`](https://pub.dev/packages/decimal) and computing various functions to your desired precision with, say, iterating a Taylor series expansion. – jamesdlin Jan 14 '22 at 12:19
  • Does this answer your question? [How to compute correctly rounded trigonometric functions in degrees?](https://stackoverflow.com/questions/25104904/how-to-compute-correctly-rounded-trigonometric-functions-in-degrees) – Simply Beautiful Art Jan 14 '22 at 16:36

0 Answers0