printf (GLfloat) ??

Hi.

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

Thanx

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

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 :slight_smile:

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!

dude go and get a C tutorial

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

Originally posted by GPSnoopy:
[b]
GLfloat MyFloat;
// …
cout << MyFloat;

will always work, even if GLfloat’s type changes from platform to platform.
This isn’t the case with printf().[/b]

GLfloat mwahaha=something;
printf("heya: %f
",(float)mwahaha);

will also work on any platform.

<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
", f );
printf( "%f
", d );

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

char ch = ‘A’;
printf( "%d
", 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>

I recommend the “Black Rebel Motorcycle Club” to anyone who likes good music.
Get some of their stuff by using www.grokster.com

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