Numerical Definitions

Numerical Definitions — mathematical constants, and floating point decomposition.

Synopsis


#include <glib.h>


#define     G_IEEE754_FLOAT_BIAS
#define     G_IEEE754_DOUBLE_BIAS
union       GFloatIEEE754;
union       GDoubleIEEE754;


#define     G_E
#define     G_LN2
#define     G_LN10
#define     G_PI
#define     G_PI_2
#define     G_PI_4
#define     G_SQRT2
#define     G_LOG_2_BASE_10

Description

GLib offers mathematical constants such as G_PI for the value of pi; many platforms have these in the C library, but some don't, the GLib versions always exist.

The GFloatIEEE754 and GDoubleIEEE754 unions are used to access the sign, mantissa and exponent of IEEE floats and doubles. These unions are defined as appropriate for a given platform. IEEE floats and doubles are supported (used for storage) by at least Intel, PPC and Sparc, for reference: http://cch.loria.fr/documentation/IEEE754/numerical_comp_guide/ncg_math.doc.html

Details

G_IEEE754_FLOAT_BIAS

#define G_IEEE754_FLOAT_BIAS	(127)

See http://cch.loria.fr/documentation/IEEE754/numerical_comp_guide/ncg_math.doc.html


G_IEEE754_DOUBLE_BIAS

#define G_IEEE754_DOUBLE_BIAS	(1023)

See http://cch.loria.fr/documentation/IEEE754/numerical_comp_guide/ncg_math.doc.html


union GFloatIEEE754

union GFloatIEEE754
{
  gfloat v_float;
  struct {
    guint mantissa : 23;
    guint biased_exponent : 8;
    guint sign : 1;
  } mpn;
};

The GFloatIEEE754 and GDoubleIEEE754 unions are used to access the sign, mantissa and exponent of IEEE floats and doubles. These unions are defined as appropriate for a given platform. IEEE floats and doubles are supported (used for storage) by at least Intel, PPC and Sparc, for reference: http://cch.loria.fr/documentation/IEEE754/numerical_comp_guide/ncg_math.doc.html


union GDoubleIEEE754

union GDoubleIEEE754
{
  gdouble v_double;
  struct {
    guint mantissa_low : 32;
    guint mantissa_high : 20;
    guint biased_exponent : 11;
    guint sign : 1;
  } mpn;
};

The GFloatIEEE754 and GDoubleIEEE754 unions are used to access the sign, mantissa and exponent of IEEE floats and doubles. These unions are defined as appropriate for a given platform. IEEE floats and doubles are supported (used for storage) by at least Intel, PPC and Sparc, for reference: http://cch.loria.fr/documentation/IEEE754/numerical_comp_guide/ncg_math.doc.html


G_E

#define G_E     2.7182818284590452354E0

The base of natural logarithms.


G_LN2

#define G_LN2   6.9314718055994530942E-1

The natural logarithm of 2.


G_LN10

#define G_LN10  2.3025850929940456840E0

The natural logarithm of 10.


G_PI

#define G_PI    3.14159265358979323846E0

The value of pi (ratio of circle's circumference to its diameter).


G_PI_2

#define G_PI_2  1.57079632679489661923E0

Pi divided by 2.


G_PI_4

#define G_PI_4  0.78539816339744830962E0

Pi divided by 4.


G_SQRT2

#define G_SQRT2 1.4142135623730950488E0

The square root of two.


G_LOG_2_BASE_10

#define G_LOG_2_BASE_10		(0.30102999566398119521)

Used for fooling around with float formats, see http://cch.loria.fr/documentation/IEEE754/numerical_comp_guide/ncg_math.doc.html

See Also

http://cch.loria.fr/documentation/IEEE754/numerical_comp_guide/ncg_math.doc.html