[try Beta version]
Not logged in

 
int n float

Oct 1, 2013 at 6:05pm
when do we use both int n float at the same time and why
Oct 1, 2013 at 6:08pm
Can you explain further? please!
Oct 1, 2013 at 6:39pm
Use int for integer numbers ex: 1 , 9, 100 , -1 , -5
Use float for rational numbers with up to about 7: 0.000000009f , 1.234f , 1.30003f 1222.231f //excluding the zeros
Use double for twice the precision of floats 1.22222222222 , 1.999999 12222.2321
Oct 1, 2013 at 7:31pm
You have many choices when it comes to the fundamental types. So how do you know which type to use? well, if you need an integer value, you're best off using int, that's because int is generally implemented so that it occupies an amount of memory that is most efficiently handled by the computer and if you need a floating pointer number (ex: 1.5251) you're best off using float, which again is likely to be implemented so that it occupies an amount of memory that is most efficiently handled by the computer.
Oct 1, 2013 at 7:38pm
Unless you absolutely have to, never use the actual float type. Use double instead.

EDIT: Changed "long double" to "double" as requested by JLBorges.
Last edited on Oct 1, 2013 at 7:47pm
Oct 1, 2013 at 7:45pm
Prefer using double as the default floating point type.
Unless there is a specific requirement, avoid the use of float or long double.
Last edited on Oct 1, 2013 at 7:45pm
Oct 1, 2013 at 11:10pm
If you need to use a long double you are using some really large numbers and would probably be better off just making a custom class IMO to make it more precise ( for integers anyways ).
Oct 1, 2013 at 11:23pm
@giblit: unless you need so much precision that you don't care for the efficiency, making your own class instead of using long double directly seems like a really bad idea.
Oct 2, 2013 at 1:39am
how would it be a bad idea to make a custom integer class? It would be a lot more precise than doing floating point calculations

1 + 1 = 2
.99999999999999 + .9999999999999 != 2
Last edited on Oct 2, 2013 at 1:40am
Oct 2, 2013 at 2:12am
Convince me that there's a minimal performance decrease and I'll believe you ;p
Oct 2, 2013 at 2:22am
I'm not sure about performance but it would be slightly more accurate if you really cared about like 100000000000000000000000000000000000000000 + 1000000000000000000000000000000000000000000
Oct 2, 2013 at 2:27am
I'm willing to bet the performance penalty makes it completely not worth it.
Oct 2, 2013 at 8:47am
> If you need to use a long double you are using some really large numbers

The range of long double is not all that much larger than the range of double on most architectures.

For instance, on GCC x86 and x86_64, the value representation of a long double is 10 bytes (80-bit extended precision format). sizeof( long double ), which is the amount of memory occupied by the object representation of long double is a larger value (12 or 16 bytes) to meet alignment requirements. SSE/SSE2/SSE3 instructions, which are limited to operations on (multiples of) 64-bits, are way faster than operations on the archaic FPU x87 which supports 80-bit floating point operations.

GCC 4.3 and above on x86_64 has a (nonstandard) __float128 type which has true quadruple precision.
Nov 2, 2013 at 7:18am
thank u all ...
Topic archived. No new replies allowed.