Menu

#695 wrong output of trigonometric funtions for large value of argument

open
nobody
None
compiler
2013-10-05
2013-07-31
Simone Fusi
No

When the argument of trigonometric functions (sin cos tan) is sufficiently large (>= 1e19) in module, the output is wrong. In particular sin and cos output the argument instead of the function. cos(1e19) = 1e19

code example:
OPEN "cos.txt" FOR OUTPUT AS #1
Dim m as long
FOR m = 1 TO 100
PRINT #1, cos(10^(m)), cos(-10^(m)), sin(10^(m)),sin(-10^(m)), tan(10^(m)), tan(-10^(m))
next m
CLOSE #1

Discussion

  • Matthew

    Matthew - 2013-07-31

    The functions break at 2^63. At this point, double-precision values have a granularity of 1024. Since sin and cos have a periodicity of ~6.28 (and tan a periodicity of half that), this renders the values pretty much meaningless anyway.

    I'd suggest a way of calculating the sine/cosine of very large angles using recursion and the double angle formula, but in a quick experiment it seems the error tends to blow up, so it would become unreliable pretty quickly.

     
  • dkl

    dkl - 2013-10-05

    Am I right thinking this is the normal behaviour then? (i.e. we can't really fix this, without using floats with more precision than 64 bits)

     

Log in to post a comment.

MongoDB Logo MongoDB