javajava-mecldc

How to write a cosine/ceil/floor calculator in java


Math.cos, Math.ceil, and Math.floor are all not supported while developing for CLDC 1.0 in Java me. I want to write these functions manually myself but I'm totally clueless on how to do this. Has anyone encountered this problem before? Any code guide or sample?

UPDATE:

From this site

I can calculate cosine by

cos(x) = 1 - x2/2! + x4/4! - x6/6! + x8/8!...

but then the problem of accuracy of course arises,

and I'm thinking Math.Ceiling should be the same as:

double d;
if((int)d - d > 0) return int(d) + 1;
else return (int) d;

and floor should be opposite...


Solution

  • Math.functions.... is not available CLDC 1.0

    I think, you have to use a third party library like MicroFloat to use J2SE (add, subtract,multiply, divide, mod, comparisons, typecasts) as well as java.lang.Math (sin, cos, exp, pow, log, etc.)