Boost logo

Boost :

From: Jens Maurer (Jens.Maurer_at_[hidden])
Date: 2001-02-12 14:44:03

k.hagan_at_[hidden] wrote:
> On the subject of providing constants in float, double and long
> double flavours...
> 1 x86 family processors have built-in constants for pi and several
> logarithms which are accurate to 66 bits.
I've tried this with gcc on Linux:

#include <iostream>

template<class T>
struct mathconst
  static const T pi() {
    long double x;
    __asm__("fldpi" : "=t" (x));
    return x;

int main()
  std::cout << mathconst<long double>::pi()*2.5 << std::endl;

Looking at the assembler output, this looks fine and does what we
want. However, using mathconst<double> instead of mathconst<long double>
makes gcc store and re-load the value, possibly to get it adequately
rounded. You can get around that in the "double" case by declaring
"x" of type "double" instead.

It seems that our current discussion does not preclude the use of
built-in constants.

Jens Maurer

Boost list run by bdawes at, gregod at, cpdaniel at, john at