Re: union



Michael Mair wrote:
> ramu wrote:
> > Vladimir S. Oka wrote:
> >
> <snip>
>
> >>>PS
> >>>Don't get into habit of using floats. Use double instead.
> >
> > Will you please tell that why we have to use double instead of floats?
>
> float has fewer significant digits and you get inexact results
> _much_ earlier. Usually, you cannot even store all long values
> exactly in a float variable.
> double has only slightly better guarantees with respect to
> the number of digits but in practice has many more.
> Using double thus means that you most of the time can forget
> about precision (numerics and excessive financial calculation
> excluded).
> <OT> Apart from that, double is definitely not slower on modern
> host PCs </OT>

Also, in many context in a C program, floats will be promoted/converted
to doubles anyway (and maybe then back to float again, if you assign
expression result to a float variable), thus negating any performance
gains you may think you got.

Cheers

Vladimir


> Cheers
> Michael
> --
> E-Mail: Mine is an /at/ gmx /dot/ de address.

.



Relevant Pages

  • Re: Measuring time differences
    ... Michael Mair wrote: ... > Dominik Wallner wrote: ... you are using float; ... Prev by Date: ...
    (comp.lang.c)
  • Re: Type punning
    ... Michael Mair wrote: ... float f; uint32_t i; ... That is, if I know uint32_t exists and the sizes of the objects are identical, will 'i' and 'f' have identical bit patterns after the assignments? ... if I know the bit pattern of 'i' is not a trap representation for 'float'? ...
    (comp.lang.c)
  • Re: how to use PI in c99
    ... if float operations are faster than doubles, ... more than 16 significant digits, or, whatever the relative ... i thought the compiler would optimize it and only use floats. ...
    (comp.lang.c)
  • Re: floating point representation
    ... > alf wrote: ... Because on a float where i can represent the significant with 24 bits i ... > Note that double is good for more than 10 significant digits, ...
    (comp.sys.mac.programmer.help)
  • Re: union
    ... Vladimir S. Oka wrote: ... Writing a value into one member, ... > it, as a float, it happens you get a float 0.00000. ... > Don't get into habit of using floats. ...
    (comp.lang.c)