[Lemon-devel] Math constants in C++

Alpár Jüttner alpar at cs.elte.hu
Sat Feb 2 08:21:14 CET 2008


Hi,

I'm about to write a lemon include file providing math constants. This
however raises more questions.

      * Is that OK to declare all these constants as 'const long
        double'? In math.h (in gcc), there are two series of math
        constants, e.g. M_LN2 is provides enough digits only for double
        while M_LN2l is the long double declaration.
      * Do we need to provide all of the original math.h constants for
        'compatibility'? For example there are several constants which
        are just some other constants multiplied by two. Nowadays,
        compilers will optimize the expressons like '2*M_PI', won't
        they?
      * How to call these constants? In math.h they are #define's, thus
        we cannot use the same name. As all these constants are prefixed
        with M_, my first idea was to just remove this prefix. For PI or
        LOG2 this seems quite reasonable. However,
              * what about M_E? Isn't it too harsh have a constant E?
                Actually, it is in our namespace, so it will not cause
                name conflict.
              * what about M_1_PI, M_2_PI etc.? (These define 1/pi and
                2/pi respectively) We cannot call then 1_PI, or 2_PI.
                But do we need them at all?


Best regards,
Alpar





More information about the Lemon-devel mailing list