win32
asked on
Float or Double
Hey I want to use the fastest type,
is i float, or double ?
My code is like that:
float/double angle;
..
..=Math.sin(angle);
is i float, or double ?
My code is like that:
float/double angle;
..
..=Math.sin(angle);
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks I just wanted to be sure, before going through my code !
ASKER
Hmm I am sure that float is fastest, but, when i write, like this
float x, angle;
x = Math.sin(angle);
-------------
Compile error occure, (cast error)
So I have to write
x = (float) Math.sin(..);
Ok Math.sin() returns double, where can i find a sin() that returns float ??
You say it is faster to use float, but I don't think so if I have to cast the result !!
And also I want to optimise my code (so I nead a sin() that returns flaot)
PS. Please help, me ! :-)
float x, angle;
x = Math.sin(angle);
-------------
Compile error occure, (cast error)
So I have to write
x = (float) Math.sin(..);
Ok Math.sin() returns double, where can i find a sin() that returns float ??
You say it is faster to use float, but I don't think so if I have to cast the result !!
And also I want to optimise my code (so I nead a sin() that returns flaot)
PS. Please help, me ! :-)
Unfortunately, I think we're all stuck with the double sin() because Sun didn't provide a method that returns float. And your casting statement will it worse, because casting needs CPU time.
So, either you store your results in double variable and cast them LATER after you finish the time-critical operation you're doing,
OR
if you're looking for speed, you can use native code from Java, but his means that your code will NOT be pure Java and will run only the platform on which you have the native library.
By the way, the method sin() takes a 'double' argument, this means that actually, there is an implicit conversion taking place to convert 'angle' to double.
So, either you store your results in double variable and cast them LATER after you finish the time-critical operation you're doing,
OR
if you're looking for speed, you can use native code from Java, but his means that your code will NOT be pure Java and will run only the platform on which you have the native library.
By the way, the method sin() takes a 'double' argument, this means that actually, there is an implicit conversion taking place to convert 'angle' to double.
ASKER
Year thats a problem, it seems that it goes faster with double, Sorry I can't wait to cast it, the calculation is needed inside a Render loop in Java3D, so I nead the calculation for eatch frame * 5 times, I am running (best case) 20FPS, thats 100 times pr. sec
If you want to take a look at the code, it you can get it at:
www.student.dtu.dk/~c971448/3ugers
I will upload it in 2 dayes !
But thanks for the help !
If you want to take a look at the code, it you can get it at:
www.student.dtu.dk/~c971448/3ugers
I will upload it in 2 dayes !
But thanks for the help !
ASKER
Hmm year I could also use precalculation of the angles I am using, but by doing that I think my code looks like old C. I want to keap it object oriented !!
float