Click to See Complete Forum and Search --> : What


wishkah353
09-24-2008, 12:55 PM
error: possible loss of precision
found: double
required: float

float y = radius * Math.sin( i * twoPi / sections );
---------------^
whyyyyyyyyyyyyyyyyyyyyyyyy? i've tried changing the variable to every last type of number i could find and nothings working =(

public void display (GLAutoDrawable drawable) {
final GL gl = drawable.getGL ();

float i;
float sections = (float)(16);
float radius = (float)(0.8f); //radius
float twoPi = (float)(2.0f * 3.14159f);

gl.glClearColor ( 0.0f, 0.0f, 0.0f, 0.0f );
gl.glClear ( GL.GL_COLOR_BUFFER_BIT );
gl.glColor3f ( 1.0f, 1.0f, 1.0f );
gl.glBegin ( GL.GL_TRIANGLE_FAN );

gl.glVertex2f ( 0.0f, 0.0f );
for( i = 0; i <= sections; i++ ) {
float x = radius * Math.cos(i * twoPi / sections);
float y = radius * Math.sin(i * twoPi / sections);
gl.glVertex2f ( x, y );
}

FourCourtJester
09-24-2008, 01:10 PM
It only complains for Math.sin, not Math.cos ?

wishkah353
09-24-2008, 01:55 PM
sorry yes, i get an error for both of them.

FourCourtJester
09-24-2008, 02:04 PM
After some quick research, my guess is that Math.sin and Math.cos return double types. A double multiplied by a float gets upgraded to a double.

Doubles hold more decimal points, which would be the 'loss in precision' by trying to save a double into a float.

Can you change your x and y into doubles? Should solve the issue, or at least give a different error.

Edit:http://www.codingdiary.com/developers/developers/diary/javaapi/java/lang/SampleCode/CosMathExampleCode.html confirms that Math.cos and Math.sin returns double values.

wishkah353
09-24-2008, 02:15 PM
http://img90.imageshack.us/img90/9538/65099995ya7.jpg

error i get when i change.

FourCourtJester
09-24-2008, 02:24 PM
try replacing glVertex2f with glVertex2d (or the equivalent method that accepts doubles instead of floats as arguments)

wishkah353
09-24-2008, 02:25 PM
any chance of some help within the next 30 min? =p

game over by 3:00pm =(

ive been searching everywhere and came across typecasting from double to float?

all i found were string examples. anyone familiar withthis and could send me on my way rly quick?

just need to know how to change the Math.cos and sin from double (what they return) to float? or what would be the best way to do this?

wishkah353
09-24-2008, 02:29 PM
try replacing glVertex2f with glVertex2d (or the equivalent method that accepts doubles instead of floats as arguments)

YOU ARE THE MAN AND A GENIUS XD

TY SOO MUCH

http://img409.imageshack.us/img409/8678/89011026dg4.jpg

FourCourtJester
09-24-2008, 02:35 PM
No worries, happy to help :)