1

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...

gnat
  • 6,213
  • 108
  • 53
  • 73
Chibueze Opata
  • 9,856
  • 7
  • 42
  • 65
  • related questions: [Asin, Acos, Atan in J2ME](http://stackoverflow.com/questions/3989764/asin-acos-atan-in-j2me), [Trigonometry in CLDC 1.0 / MIDP 2.0 application](http://stackoverflow.com/questions/1793534/trigonometry-in-cldc-1-0-midp-2-0-application) – gnat Apr 27 '12 at 09:39
  • unfortunately first one doesn't solve the problem, second one has dead links... with the exception of AurA's suggestion which also happens to be your suggestion on the page. – Chibueze Opata Apr 27 '12 at 10:10
  • and I always thinknig writing these functions myself and taking a look later at others who tried the code helps me make out better code... but I finally decided to write two separate applications as it was easy to predict that future complications will rise... – Chibueze Opata Apr 27 '12 at 10:13
  • Before I toss in some code I would like to get you to refine your question. You want rough equivalents to the Math.cos(double) Math.ceil(double) and Math.floor(double). Do you need to support any other functions? Have you considered just using the exact code of those methods? Do you have performance or memory requirements that would preclude you doing that? – Jim Apr 27 '12 at 06:34
  • You should post this as a comment, the problem is that these Math functions are not available when you set target platform to CLDC 1.0. – Chibueze Opata Apr 27 '12 at 06:38
  • You can still take a normal Java SE library and copy the source code from that library's `java.lang.Math` class. – Roland Illig Apr 27 '12 at 06:41
  • but shouldn't that be compiled already? where can I find the raw java file? – Chibueze Opata Apr 27 '12 at 06:42
  • @RolandIllig: I've seen one class like that. It just says "native" and has no code. Or was that a dream..? – Oleh Prypin Apr 27 '12 at 07:08
  • Ok, then look at fdlibm, which is implemented in C, but that is the definitive source. – Roland Illig Apr 27 '12 at 19:01

1 Answers1

2

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.)

AurA
  • 12,135
  • 7
  • 46
  • 63