Android Question Error in Sine function

Roger Daley

Well-Known Member
Licensed User
Longtime User
Hi All,

I have found that B4A gives me an error in trig functions and I'm wondering if anyone has any clues of how to fix it.

Example: sin(cPI) gives the result of "1.2246468E-16", should be zero.

Similar sort of problem with SinD, Cos, Tan Etc.

I know this is a small error but I also know it shouldn't be there.


Regards Roger
 

Roger Daley

Well-Known Member
Licensed User
Longtime User
B4A Sin keyword simply calls the native Math.Sin with the value of Math.PI. This means that the rounding error (which is expected) does not happen in B4A layer.


Thanks Erel,

Fair enough, not a B4A error. I'll give some thought to catching the known problems. [ie Zero/Hypotenuse.]

Regards Roger
 
Last edited:
Upvote 0

Roger Daley

Well-Known Member
Licensed User
Longtime User
1e-16 is a very small number (0.000000000000001). Assuming that you convert the number to a string with NumberFormat or NumberFormat2 it will always appear as 0.


Thanks again Erel.


Rounding down to 15 digits solved the issue. 15 decimal places more than enough for me.
"disp(1) = Round2 (disp(1), 15)" worked. [As would have NumberFormat]

Regards Roger
 
Upvote 0
Top