Skip to main content

Whats with the "f" thing?

6 replies [Last post]
Anonymous

In a lot of the programs i hav seen for java 3d they create objects with the paramaters of, for example, (0.0f, 0.2f, 0.3f) for a vector. What is they f there for and y is it needed? i thought it is there beacause the constuctors expect something of type float but i see no reason for having the f there.

if anyone could explain that would be great.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Matthew Hilliard

No. It simply specifies which type it is for the compiler.

0 is an int
0L is a long
0f and 0.0f are floats
0.0 is a double
(float) 0.0 is a double cast as a float.

The compiler may promote a value to a higher resolution, but it will NOT
cast it to a lower one.

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@java3d.dev.java.net
For additional commands, e-mail: interest-help@java3d.dev.java.net

Anonymous

Thanks so much for the info it makes a lot more sence now then it did before.

Anonymous

i get why its a float i dont get y u need to put the f there. Does it act like casting it to float?

Gilson Laurent

Hello

> Does it act like casting it to float? ---

Yes (and no). 0.0f = ((float)0.0).

In the f-version the number gets saved as float in the class-file. The
casting-version saves the number as double and casts to float at runtime.

(I don't know if the newer compiler still do it that way...)

cu
[att1.dat]

Gilson Laurent

Hello

0 => byte, short, int, long, double or float
0.0 => double (and NOT float)
0.0d => double
0.0f => float.

so "new Vector3f (0,0,0)" will work. "new Vector3f (0.0 ,0.0 ,0.0 )" will NOT
work. "new Vector3f (0.0f ,0.0f ,0.0f )" or "new Vector3f ((foat)0.0 ,(foat)
0.0 ,(foat)0.0 )" works.

That's why.

> In a lot of the programs i hav seen for java 3d they create objects with
> the paramaters of, for example, (0.0f, 0.2f, 0.3f) for a vector. What is
> they f there for and y is it needed? i thought it is there beacause the
> constuctors expect something of type float but i see no reason for having
> the f there.
>
> if anyone could explain that would be great.
> ---
> [Message sent by forum member 'Stoyan' (Stoyan)]
>
> http://www.javadesktop.org/forums/thread.jspa?messageID=41868&#41868
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@java3d.dev.java.net
> For additional commands, e-mail: interest-help@java3d.dev.java.net
[att1.dat]

Matthew Hilliard

Without the "f," Java will believe you're passing it a double, and you'll
wind up using the double version of the same class.
All of these classes will accomplish the same thing with a double as with a
float, but the memory requirements for a double are (for good reason)
double what they are for a float, and the performance for doubles are on
most machines less than they are for floats. The flipside to using a
double is you get more significant bits and you gain a higher level of
precision (less error) when factoring them into equations.

doubles and floats can be used interchangeably in most cases.

Matt

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@java3d.dev.java.net
For additional commands, e-mail: interest-help@java3d.dev.java.net