<refentry id="glib-Numerical-Definitions"> <refmeta> <refentrytitle>Numerical Definitions</refentrytitle> <manvolnum>3</manvolnum> <refmiscinfo>GLIB Library</refmiscinfo> </refmeta> <refnamediv> <refname>Numerical Definitions</refname><refpurpose>mathematical constants, and floating point decomposition.</refpurpose> </refnamediv> <refsynopsisdiv><title>Synopsis</title> <synopsis> #include <glib.h> #define <link linkend="G-IEEE754-FLOAT-BIAS-CAPS">G_IEEE754_FLOAT_BIAS</link> #define <link linkend="G-IEEE754-DOUBLE-BIAS-CAPS">G_IEEE754_DOUBLE_BIAS</link> union <link linkend="GFloatIEEE754">GFloatIEEE754</link>; union <link linkend="GDoubleIEEE754">GDoubleIEEE754</link>; #define <link linkend="G-E-CAPS">G_E</link> #define <link linkend="G-LN2-CAPS">G_LN2</link> #define <link linkend="G-LN10-CAPS">G_LN10</link> #define <link linkend="G-PI-CAPS">G_PI</link> #define <link linkend="G-PI-2-CAPS">G_PI_2</link> #define <link linkend="G-PI-4-CAPS">G_PI_4</link> #define <link linkend="G-SQRT2-CAPS">G_SQRT2</link> #define <link linkend="G-LOG-2-BASE-10-CAPS">G_LOG_2_BASE_10</link> </synopsis> </refsynopsisdiv> <refsect1> <title>Description</title> <para> GLib offers mathematical constants such as <link linkend="G-PI-CAPS"><type>G_PI</type></link> for the value of pi; many platforms have these in the C library, but some don't, the GLib versions always exist. </para> <para> The <link linkend="GFloatIEEE754"><type>GFloatIEEE754</type></link> and <link linkend="GDoubleIEEE754"><type>GDoubleIEEE754</type></link> 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: <ulink url="http://cch.loria.fr/documentation/IEEE754/numerical_comp_guide/ncg_math.doc.html">http://cch.loria.fr/documentation/IEEE754/numerical_comp_guide/ncg_math.doc.html</ulink> </para> </refsect1> <refsect1> <title>Details</title> <refsect2> <title><anchor id="G-IEEE754-FLOAT-BIAS-CAPS"/>G_IEEE754_FLOAT_BIAS</title> <indexterm><primary>G_IEEE754_FLOAT_BIAS</primary></indexterm><programlisting>#define G_IEEE754_FLOAT_BIAS (127) </programlisting> <para> See <ulink url="http://cch.loria.fr/documentation/IEEE754/numerical_comp_guide/ncg_math.doc.html">http://cch.loria.fr/documentation/IEEE754/numerical_comp_guide/ncg_math.doc.html</ulink> </para></refsect2> <refsect2> <title><anchor id="G-IEEE754-DOUBLE-BIAS-CAPS"/>G_IEEE754_DOUBLE_BIAS</title> <indexterm><primary>G_IEEE754_DOUBLE_BIAS</primary></indexterm><programlisting>#define G_IEEE754_DOUBLE_BIAS (1023) </programlisting> <para> See <ulink url="http://cch.loria.fr/documentation/IEEE754/numerical_comp_guide/ncg_math.doc.html">http://cch.loria.fr/documentation/IEEE754/numerical_comp_guide/ncg_math.doc.html</ulink> </para></refsect2> <refsect2> <title><anchor id="GFloatIEEE754"/>union GFloatIEEE754</title> <indexterm><primary>GFloatIEEE754</primary></indexterm><programlisting>union GFloatIEEE754 { gfloat v_float; struct { guint mantissa : 23; guint biased_exponent : 8; guint sign : 1; } mpn; }; </programlisting> <para> The <link linkend="GFloatIEEE754"><type>GFloatIEEE754</type></link> and <link linkend="GDoubleIEEE754"><type>GDoubleIEEE754</type></link> 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: <ulink url="http://cch.loria.fr/documentation/IEEE754/numerical_comp_guide/ncg_math.doc.html">http://cch.loria.fr/documentation/IEEE754/numerical_comp_guide/ncg_math.doc.html</ulink> </para></refsect2> <refsect2> <title><anchor id="GDoubleIEEE754"/>union GDoubleIEEE754</title> <indexterm><primary>GDoubleIEEE754</primary></indexterm><programlisting>union GDoubleIEEE754 { gdouble v_double; struct { guint mantissa_low : 32; guint mantissa_high : 20; guint biased_exponent : 11; guint sign : 1; } mpn; }; </programlisting> <para> The <link linkend="GFloatIEEE754"><type>GFloatIEEE754</type></link> and <link linkend="GDoubleIEEE754"><type>GDoubleIEEE754</type></link> 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: <ulink url="http://cch.loria.fr/documentation/IEEE754/numerical_comp_guide/ncg_math.doc.html">http://cch.loria.fr/documentation/IEEE754/numerical_comp_guide/ncg_math.doc.html</ulink> </para></refsect2> <refsect2> <title><anchor id="G-E-CAPS"/>G_E</title> <indexterm><primary>G_E</primary></indexterm><programlisting>#define G_E 2.7182818284590452354E0 </programlisting> <para> The base of natural logarithms. </para></refsect2> <refsect2> <title><anchor id="G-LN2-CAPS"/>G_LN2</title> <indexterm><primary>G_LN2</primary></indexterm><programlisting>#define G_LN2 6.9314718055994530942E-1 </programlisting> <para> The natural logarithm of 2. </para></refsect2> <refsect2> <title><anchor id="G-LN10-CAPS"/>G_LN10</title> <indexterm><primary>G_LN10</primary></indexterm><programlisting>#define G_LN10 2.3025850929940456840E0 </programlisting> <para> The natural logarithm of 10. </para></refsect2> <refsect2> <title><anchor id="G-PI-CAPS"/>G_PI</title> <indexterm><primary>G_PI</primary></indexterm><programlisting>#define G_PI 3.14159265358979323846E0 </programlisting> <para> The value of pi (ratio of circle's circumference to its diameter). </para></refsect2> <refsect2> <title><anchor id="G-PI-2-CAPS"/>G_PI_2</title> <indexterm><primary>G_PI_2</primary></indexterm><programlisting>#define G_PI_2 1.57079632679489661923E0 </programlisting> <para> Pi divided by 2. </para></refsect2> <refsect2> <title><anchor id="G-PI-4-CAPS"/>G_PI_4</title> <indexterm><primary>G_PI_4</primary></indexterm><programlisting>#define G_PI_4 0.78539816339744830962E0 </programlisting> <para> Pi divided by 4. </para></refsect2> <refsect2> <title><anchor id="G-SQRT2-CAPS"/>G_SQRT2</title> <indexterm><primary>G_SQRT2</primary></indexterm><programlisting>#define G_SQRT2 1.4142135623730950488E0 </programlisting> <para> The square root of two. </para></refsect2> <refsect2> <title><anchor id="G-LOG-2-BASE-10-CAPS"/>G_LOG_2_BASE_10</title> <indexterm><primary>G_LOG_2_BASE_10</primary></indexterm><programlisting>#define G_LOG_2_BASE_10 (0.30102999566398119521) </programlisting> <para> Used for fooling around with float formats, see <ulink url="http://cch.loria.fr/documentation/IEEE754/numerical_comp_guide/ncg_math.doc.html">http://cch.loria.fr/documentation/IEEE754/numerical_comp_guide/ncg_math.doc.html</ulink> </para></refsect2> </refsect1> <refsect1> <title>See Also</title> <para> <ulink url="http://cch.loria.fr/documentation/IEEE754/numerical_comp_guide/ncg_math.doc.html">http://cch.loria.fr/documentation/IEEE754/numerical_comp_guide/ncg_math.doc.html</ulink> </para> </refsect1> </refentry>