posted 13 years ago

Ok, I've been trying to to find a way of using trig functions in my code, but I've been having nothing but problems.

I've been using the henson Float class, available at:

http://henson.newmail.ru/j2me/Float.htm

But the answers it gives me for the cos and sin functions are pure nonsense. I'm trying to convert the degrees to radians and then run the cos and sin functions on them.

It seemed to work fine for a test value of 60 degrees (1.047 radians), giving me the approximately correct results of cos 1.047 = 0.5001 and sin 1.047 = 0.866

But when I try it with anything else the results are utterly wrong. For example 45 degrees (2 radians), instead of getting 0.707 for both it gives me cos 2 = -0.416 and sin 2 = 0.909 ?

Why does it work for only the one value ?

Has anybody got this float class to work, ever ?

Has anybody got any alternatives ?

Please help me , I'm getting annoyed and desperate for a solution. I've also tried using MathFP, but that kept giving me wrong class name error.

I've been using the henson Float class, available at:

http://henson.newmail.ru/j2me/Float.htm

But the answers it gives me for the cos and sin functions are pure nonsense. I'm trying to convert the degrees to radians and then run the cos and sin functions on them.

It seemed to work fine for a test value of 60 degrees (1.047 radians), giving me the approximately correct results of cos 1.047 = 0.5001 and sin 1.047 = 0.866

But when I try it with anything else the results are utterly wrong. For example 45 degrees (2 radians), instead of getting 0.707 for both it gives me cos 2 = -0.416 and sin 2 = 0.909 ?

Why does it work for only the one value ?

Has anybody got this float class to work, ever ?

Has anybody got any alternatives ?

Please help me , I'm getting annoyed and desperate for a solution. I've also tried using MathFP, but that kept giving me wrong class name error.

Andy Robinson

Greenhorn

Posts: 10

Layne Lund

Ranch Hand

Posts: 3061

posted 13 years ago

After a little more search, I found out that it is CLDC 1.0 that specifically rules out floating point arithmetic. Since MIDP is built on CLDC, it just inherits this limitation. Perhaps more recent versions of CLDC have introduced floating point arithmetic, though.

Sorry that this doesn't answer your quesiton completely, but I just wanted to clarify that such limitations DO exist.

Layne

Sorry that this doesn't answer your quesiton completely, but I just wanted to clarify that such limitations DO exist.

Layne

Did you see how Paul cut 87% off of his electric heat bill with 82 watts of micro heaters? |