[linux-dvb] slightly OT: Floats at compile time

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Patrick Boettcher wrote:
>
> My question is: Is it save to assume, that all compilers calculate the 
> following assignment at compile time?
> 
> int value = 0.523 * 65535;

Gcc does it at compile time (as do most compilers).  Whether _all_?
I don't know.  There are pretty strange C compilers and afaics the
standard allows run-time computation.

However, gcc also computes

    #define value ((int)(0.523 * 65535))

at compile time.


But if you prefer the int var, IMHO better is:

    static const int value = 0.534 * 65535 + 0.5;

so that the compiler may optimize further arithmetic with <value>.


> Presuming it is true, would kernel guys accept such a thing: using 
> floats for compile time constants?

You'd better ask that on lkml.  There'll be at least one who will
have an objection ;-)

Ciao, ET.


[Index of Archives]     [Linux Media]     [Video 4 Linux]     [Asterisk]     [Samba]     [Xorg]     [Xfree86]     [Linux USB]

  Powered by Linux