# Android QuestionError in Sine function

#### Roger Daley

##### Well-Known Member
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

#### LucaMs

##### Expert
Longtime User
Why sin(cPI) shoul be zero? sin(3.14....) can't be zero.

#### Erel

##### B4X founder
Staff member
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.

#### Roger Daley

##### Well-Known Member
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:

#### Erel

##### B4X founder
Staff member
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.

#### Roger Daley

##### Well-Known Member
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

Replies
27
Views
6K
Replies
10
Views
5K
Android Code Snippet NB6 class - additional functions
Replies
11
Views
8K
Replies
421
Views
187K
Replies
28
Views
28K