Trig function values (Sin 180 , Cos 90 etc) not exactly 0

65 views
Skip to first unread message

Virdinetics

unread,
Aug 30, 2019, 3:09:09 PM8/30/19
to MIT App Inventor Forum
Hello forum,

I am using sin 180, sin 360, cos 90, cos 270 etc in one of my apps. These should be 0, but I get numbers like 1.7949E-9 etc.
I appreciate that this is close to 0, but due to this discrepancy I am getting errors in my app.

Is there a solution for this problem in the back end ?

Thanks,

Virdinetics

TimAI2

unread,
Aug 30, 2019, 4:37:57 PM8/30/19
to MIT App Inventor Forum
Like so ?

blocksdec5.png


Use the absolute block to remove the minus sign


Virdinetics

unread,
Aug 31, 2019, 11:36:25 AM8/31/19
to MIT App Inventor Forum
Yes there are several ways to get rid of the problem by programming. But I guess the basic primitive should give the correct answers. Or at least update the documentation to say that these items will not give exact values and the users are aware of the error. 

So my question is if the developers could look into the problem in the back-end programming rectify the problem there ?

Cheers

SteveJG

unread,
Aug 31, 2019, 12:00:35 PM8/31/19
to MIT App Inventor Forum
There is no problem   App Inventor and Android use FloatingPoint Math ....0.0000001 for all practical purposes is zero.  App Inventor uses the Android Math libraries. 

Regards,
Steve

Evan Patton

unread,
Sep 3, 2019, 10:02:28 AM9/3/19
to MIT App Inventor Forum
It seems reasonable to add these as special test cases. The issue here is that our blocks use degrees but the underlying methods use radians. We internally convert from degrees to radians, but doing so introduces a small amount of error due to the inclusion of pi in the computation. Since these are common enough cases it seems like we should be able to do this.

Regards,
Evan
Reply all
Reply to author
Forward
0 new messages