PDA

View Full Version : printf (GLfloat) ??



vofka
04-17-2002, 01:39 PM
Hi.

How can I print my GLfloat variable?
And is it possible to take a sqrt() from it?

Thanx

j
04-17-2002, 01:46 PM
A GLfloat is the same as a float on all platforms I know of, so you can just go printf("%f", yourGLfloat);, and sqrt() works perfectly fine too.

I don't see how this is an advanced question, especially considering that you could find out in 30 seconds by trying it out in your code. Please at least try before you ask something like this.

j

jwatte
04-17-2002, 05:26 PM
Even better than trying it out in code (where it may work "by accident") is to just look it up in the headers. Headers aren't magic, they're just code, and they're usually more accurate than documentation when it comes to implementation details :-)

If you've previously been scared of system headers, or don't know where they live, now's the time to change for the better!

S4w
04-20-2002, 12:19 PM
dude go and get a C tutorial
http://www.opengl.org/discussion_boards/ubb/smile.gif

GPSnoopy
04-20-2002, 12:30 PM
If you can, use the C++ solution: the object-oriented approach solves your problem.


GLfloat MyFloat;
// ...
cout << MyFloat;


will always work, even if GLfloat's type changes from platform to platform.
This isn't the case with printf().

sqrt() only takes a double as input (sqrtf takes a float), but sqrt(MyFloat) or sqrt((double) MyFloat) should work anyway.

[This message has been edited by GPSnoopy (edited 04-20-2002).]

zeckensack
04-20-2002, 12:35 PM
Originally posted by GPSnoopy:

GLfloat MyFloat;
// ...
cout << MyFloat;


will always work, even if GLfloat's type changes from platform to platform.
This isn't the case with printf().
GLfloat mwahaha=something;
printf("heya: %f\n",(float)mwahaha);
will also work on any platform.

jwatte
04-20-2002, 01:09 PM
<rant topic=off>
I'm really quite amazed at the level of mis-understanding about basic features of the language and library are floating around lately. Must be all that mushy Java stuff luring people into a false sense of understanding.

printf() takes varargs. All floating-point arguments are promoted to double precision when being passed through varargs. Thus, these two calls will BOTH work, because %f means "a floating point value, as promoted".

float f = 1.f;
double d = 1.;
printf( "%f\n", f );
printf( "%f\n", d );

Similarly, all integer arguments get promoted to int, if they're shorter than that. Thus, witness:

char ch = 'A';
printf( "%d\n", ch );

This is all very well defined in the C language, so I'm quite surprised that people would comment on the subject without actually knowing the correct behaviour.
</rant>

knackered
04-20-2002, 01:50 PM
I recommend the "Black Rebel Motorcycle Club" to anyone who likes good music.
Get some of their stuff by using www.grokster.com (http://www.grokster.com)

Something good has to come out of this pointless, pedantic thread.