glib-Numerical-Definitions.html   [plain text]


<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Numerical Definitions</title><meta name="generator" content="DocBook XSL Stylesheets V1.65.1"><link rel="home" href="index.html" title="GLib Reference Manual"><link rel="up" href="glib-fundamentals.html" title="GLib Fundamentals"><link rel="previous" href="glib-Byte-Order-Macros.html" title="Byte Order Macros"><link rel="next" href="glib-Miscellaneous-Macros.html" title="Miscellaneous Macros"><link rel="chapter" href="glib.html" title="GLib Overview"><link rel="refentry" href="glib-building.html" title="Compiling the GLib package"><link rel="refentry" href="glib-cross-compiling.html" title="Cross-compiling the GLib package"><link rel="refentry" href="glib-compiling.html" title="Compiling GLib Applications"><link rel="refentry" href="glib-running.html" title="Running GLib Applications"><link rel="refentry" href="glib-changes.html" title="Changes to GLib"><link rel="refentry" href="glib-resources.html" title="Mailing lists and bug reports"><link rel="chapter" href="glib-fundamentals.html" title="GLib Fundamentals"><link rel="refentry" href="glib-Basic-Types.html" title="Basic Types"><link rel="refentry" href="glib-Limits-of-Basic-Types.html" title="Limits of Basic Types"><link rel="refentry" href="glib-Standard-Macros.html" title="Standard Macros"><link rel="refentry" href="glib-Type-Conversion-Macros.html" title="Type Conversion Macros"><link rel="refentry" href="glib-Byte-Order-Macros.html" title="Byte Order Macros"><link rel="refentry" href="glib-Numerical-Definitions.html" title="Numerical Definitions"><link rel="refentry" href="glib-Miscellaneous-Macros.html" title="Miscellaneous Macros"><link rel="refentry" href="glib-Atomic-Operations.html" title="Atomic Operations"><link rel="chapter" href="glib-core.html" title="GLib Core Application Support"><link rel="refentry" href="glib-The-Main-Event-Loop.html" title="The Main Event Loop"><link rel="refentry" href="glib-Threads.html" title="
Threads"><link rel="refentry" href="glib-Thread-Pools.html" title="Thread Pools"><link rel="refentry" href="glib-Asynchronous-Queues.html" title="Asynchronous Queues"><link rel="refentry" href="glib-Dynamic-Loading-of-Modules.html" title="Dynamic Loading of Modules"><link rel="refentry" href="glib-Memory-Allocation.html" title="Memory Allocation"><link rel="refentry" href="glib-IO-Channels.html" title="IO Channels"><link rel="refentry" href="glib-Error-Reporting.html" title="Error Reporting"><link rel="refentry" href="glib-Warnings-and-Assertions.html" title="Message Output and Debugging Functions"><link rel="refentry" href="glib-Message-Logging.html" title="Message Logging"><link rel="chapter" href="glib-utilities.html" title="GLib Utilities"><link rel="refentry" href="glib-String-Utility-Functions.html" title="String Utility Functions"><link rel="refentry" href="glib-Character-Set-Conversion.html" title="Character Set Conversion"><link rel="refentry" href="glib-Unicode-Manipulation.html" title="Unicode Manipulation"><link rel="refentry" href="glib-I18N.html" title="Internationalization"><link rel="refentry" href="glib-Date-and-Time-Functions.html" title="Date and Time Functions"><link rel="refentry" href="glib-Random-Numbers.html" title="Random Numbers"><link rel="refentry" href="glib-Hook-Functions.html" title="Hook Functions"><link rel="refentry" href="glib-Miscellaneous-Utility-Functions.html" title="Miscellaneous Utility Functions"><link rel="refentry" href="glib-Lexical-Scanner.html" title="Lexical Scanner"><link rel="refentry" href="glib-Automatic-String-Completion.html" title="Automatic String Completion"><link rel="refentry" href="glib-Timers.html" title="Timers"><link rel="refentry" href="glib-Spawning-Processes.html" title="Spawning Processes"><link rel="refentry" href="glib-File-Utilities.html" title="File Utilities"><link rel="refentry" href="glib-Shell-related-Utilities.html" title="Shell-related Utilities"><link rel="refentry" href="glib-Glob-style-pattern-matching.html" title="Glob-style pattern matching"><link rel="refentry" href="glib-Simple-XML-Subset-Parser.html" title="Simple XML Subset Parser"><link rel="refentry" href="glib-Windows-Compatability-Functions.html" title="Windows Compatibility Functions"><link rel="chapter" href="glib-data-types.html" title="GLib Data Types"><link rel="refentry" href="glib-Memory-Chunks.html" title="Memory Chunks"><link rel="refentry" href="glib-Doubly-Linked-Lists.html" title="Doubly-Linked Lists"><link rel="refentry" href="glib-Singly-Linked-Lists.html" title="Singly-Linked Lists"><link rel="refentry" href="glib-Double-ended-Queues.html" title="Double-ended Queues"><link rel="refentry" href="glib-Trash-Stacks.html" title="Trash Stacks"><link rel="refentry" href="glib-Hash-Tables.html" title="Hash Tables"><link rel="refentry" href="glib-Strings.html" title="Strings"><link rel="refentry" href="glib-String-Chunks.html" title="String Chunks"><link rel="refentry" href="glib-Arrays.html" title="Arrays"><link rel="refentry" href="glib-Pointer-Arrays.html" title="Pointer Arrays"><link rel="refentry" href="glib-Byte-Arrays.html" title="Byte Arrays"><link rel="refentry" href="glib-Balanced-Binary-Trees.html" title="Balanced Binary Trees"><link rel="refentry" href="glib-N-ary-Trees.html" title="N-ary Trees"><link rel="refentry" href="glib-Quarks.html" title="Quarks"><link rel="refentry" href="glib-Keyed-Data-Lists.html" title="Keyed Data Lists"><link rel="refentry" href="glib-Datasets.html" title="Datasets"><link rel="refentry" href="glib-Relations-and-Tuples.html" title="Relations and Tuples"><link rel="refentry" href="glib-Caches.html" title="Caches"><link rel="refentry" href="glib-Memory-Allocators.html" title="Memory Allocators"><link rel="chapter" href="tools.html" title="GLib Tools"><link rel="refentry" href="glib-gettextize.html" title="glib-gettextize"><link rel="index" href="ix01.html" title="Index"><link rel="section" href="glib-Numerical-Definitions.html#id2992687" title="Description"><link rel="section" href="glib-Numerical-Definitions.html#id2992740" title="Details"><link rel="section" href="glib-Numerical-Definitions.html#id2993152" title="See Also"><meta name="generator" content="GTK-Doc V1.2 (XML mode)"><link rel="stylesheet" href="style.css" type="text/css"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><table class="navigation" width="100%" summary="Navigation header" cellpadding="2" cellspacing="2"><tr valign="middle"><td><a accesskey="p" href="glib-Byte-Order-Macros.html"><img src="left.png" width="24" height="24" border="0" alt="Prev"></a></td><td><a accesskey="u" href="glib-fundamentals.html"><img src="up.png" width="24" height="24" border="0" alt="Up"></a></td><td><a accesskey="h" href="index.html"><img src="home.png" width="24" height="24" border="0" alt="Home"></a></td><th width="100%" align="center">GLib Reference Manual</th><td><a accesskey="n" href="glib-Miscellaneous-Macros.html"><img src="right.png" width="24" height="24" border="0" alt="Next"></a></td></tr></table><div class="refentry" lang="en"><a name="glib-Numerical-Definitions"></a><div class="titlepage"><div></div><div></div></div><div class="refnamediv"><h2><span class="refentrytitle">Numerical Definitions</span></h2><p>Numerical Definitions &#8212; mathematical constants, and floating point decomposition.</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">

#include &lt;glib.h&gt;


#define     <a href="glib-Numerical-Definitions.html#G-IEEE754-FLOAT-BIAS-CAPS">G_IEEE754_FLOAT_BIAS</a>
#define     <a href="glib-Numerical-Definitions.html#G-IEEE754-DOUBLE-BIAS-CAPS">G_IEEE754_DOUBLE_BIAS</a>
union       <a href="glib-Numerical-Definitions.html#GFloatIEEE754">GFloatIEEE754</a>;
union       <a href="glib-Numerical-Definitions.html#GDoubleIEEE754">GDoubleIEEE754</a>;


#define     <a href="glib-Numerical-Definitions.html#G-E-CAPS">G_E</a>
#define     <a href="glib-Numerical-Definitions.html#G-LN2-CAPS">G_LN2</a>
#define     <a href="glib-Numerical-Definitions.html#G-LN10-CAPS">G_LN10</a>
#define     <a href="glib-Numerical-Definitions.html#G-PI-CAPS">G_PI</a>
#define     <a href="glib-Numerical-Definitions.html#G-PI-2-CAPS">G_PI_2</a>
#define     <a href="glib-Numerical-Definitions.html#G-PI-4-CAPS">G_PI_4</a>
#define     <a href="glib-Numerical-Definitions.html#G-SQRT2-CAPS">G_SQRT2</a>
#define     <a href="glib-Numerical-Definitions.html#G-LOG-2-BASE-10-CAPS">G_LOG_2_BASE_10</a>
</pre></div><div class="refsect1" lang="en"><a name="id2992687"></a><h2>Description</h2><p>
GLib offers mathematical constants such as <a href="glib-Numerical-Definitions.html#G-PI-CAPS"><span class="type">G_PI</span></a> for the value of pi;
many platforms have these in the C library, but some don't, the GLib
versions always exist.
</p><p>
The <a href="glib-Numerical-Definitions.html#GFloatIEEE754"><span class="type">GFloatIEEE754</span></a> and <a href="glib-Numerical-Definitions.html#GDoubleIEEE754"><span class="type">GDoubleIEEE754</span></a> 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: <a href="http://cch.loria.fr/documentation/IEEE754/numerical_comp_guide/ncg_math.doc.html" target="_top">http://cch.loria.fr/documentation/IEEE754/numerical_comp_guide/ncg_math.doc.html</a>
</p></div><div class="refsect1" lang="en"><a name="id2992740"></a><h2>Details</h2><div class="refsect2" lang="en"><a name="id2992745"></a><h3><a name="G-IEEE754-FLOAT-BIAS-CAPS"></a>G_IEEE754_FLOAT_BIAS</h3><a class="indexterm" name="id2992756"></a><pre class="programlisting">#define G_IEEE754_FLOAT_BIAS	(127)
</pre><p>
See <a href="http://cch.loria.fr/documentation/IEEE754/numerical_comp_guide/ncg_math.doc.html" target="_top">http://cch.loria.fr/documentation/IEEE754/numerical_comp_guide/ncg_math.doc.html</a>
</p></div><hr><div class="refsect2" lang="en"><a name="id2992780"></a><h3><a name="G-IEEE754-DOUBLE-BIAS-CAPS"></a>G_IEEE754_DOUBLE_BIAS</h3><a class="indexterm" name="id2992791"></a><pre class="programlisting">#define G_IEEE754_DOUBLE_BIAS	(1023)
</pre><p>
See <a href="http://cch.loria.fr/documentation/IEEE754/numerical_comp_guide/ncg_math.doc.html" target="_top">http://cch.loria.fr/documentation/IEEE754/numerical_comp_guide/ncg_math.doc.html</a>
</p></div><hr><div class="refsect2" lang="en"><a name="id2992815"></a><h3><a name="GFloatIEEE754"></a>union GFloatIEEE754</h3><a class="indexterm" name="id2992826"></a><pre class="programlisting">union GFloatIEEE754
{
  gfloat v_float;
  struct {
    guint mantissa : 23;
    guint biased_exponent : 8;
    guint sign : 1;
  } mpn;
};
</pre><p>
The <a href="glib-Numerical-Definitions.html#GFloatIEEE754"><span class="type">GFloatIEEE754</span></a> and <a href="glib-Numerical-Definitions.html#GDoubleIEEE754"><span class="type">GDoubleIEEE754</span></a> 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: 
<a href="http://cch.loria.fr/documentation/IEEE754/numerical_comp_guide/ncg_math.doc.html" target="_top">http://cch.loria.fr/documentation/IEEE754/numerical_comp_guide/ncg_math.doc.html</a>
</p></div><hr><div class="refsect2" lang="en"><a name="id2992872"></a><h3><a name="GDoubleIEEE754"></a>union GDoubleIEEE754</h3><a class="indexterm" name="id2992884"></a><pre class="programlisting">union GDoubleIEEE754
{
  gdouble v_double;
  struct {
    guint mantissa_low : 32;
    guint mantissa_high : 20;
    guint biased_exponent : 11;
    guint sign : 1;
  } mpn;
};
</pre><p>
The <a href="glib-Numerical-Definitions.html#GFloatIEEE754"><span class="type">GFloatIEEE754</span></a> and <a href="glib-Numerical-Definitions.html#GDoubleIEEE754"><span class="type">GDoubleIEEE754</span></a> 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: 
<a href="http://cch.loria.fr/documentation/IEEE754/numerical_comp_guide/ncg_math.doc.html" target="_top">http://cch.loria.fr/documentation/IEEE754/numerical_comp_guide/ncg_math.doc.html</a>
</p></div><hr><div class="refsect2" lang="en"><a name="id2992931"></a><h3><a name="G-E-CAPS"></a>G_E</h3><a class="indexterm" name="id2992941"></a><pre class="programlisting">#define G_E     2.7182818284590452354E0
</pre><p>
The base of natural logarithms.
</p></div><hr><div class="refsect2" lang="en"><a name="id2992957"></a><h3><a name="G-LN2-CAPS"></a>G_LN2</h3><a class="indexterm" name="id2992967"></a><pre class="programlisting">#define G_LN2   6.9314718055994530942E-1
</pre><p>
The natural logarithm of 2.
</p></div><hr><div class="refsect2" lang="en"><a name="id2992983"></a><h3><a name="G-LN10-CAPS"></a>G_LN10</h3><a class="indexterm" name="id2992993"></a><pre class="programlisting">#define G_LN10  2.3025850929940456840E0
</pre><p>
The natural logarithm of 10.
</p></div><hr><div class="refsect2" lang="en"><a name="id2993009"></a><h3><a name="G-PI-CAPS"></a>G_PI</h3><a class="indexterm" name="id2993019"></a><pre class="programlisting">#define G_PI    3.14159265358979323846E0
</pre><p>
The value of pi (ratio of circle's circumference to its diameter).
</p></div><hr><div class="refsect2" lang="en"><a name="id2993036"></a><h3><a name="G-PI-2-CAPS"></a>G_PI_2</h3><a class="indexterm" name="id2993046"></a><pre class="programlisting">#define G_PI_2  1.57079632679489661923E0
</pre><p>
Pi divided by 2.
</p></div><hr><div class="refsect2" lang="en"><a name="id2993062"></a><h3><a name="G-PI-4-CAPS"></a>G_PI_4</h3><a class="indexterm" name="id2993072"></a><pre class="programlisting">#define G_PI_4  0.78539816339744830962E0
</pre><p>
Pi divided by 4.
</p></div><hr><div class="refsect2" lang="en"><a name="id2993088"></a><h3><a name="G-SQRT2-CAPS"></a>G_SQRT2</h3><a class="indexterm" name="id2993098"></a><pre class="programlisting">#define G_SQRT2 1.4142135623730950488E0
</pre><p>
The square root of two.
</p></div><hr><div class="refsect2" lang="en"><a name="id2993114"></a><h3><a name="G-LOG-2-BASE-10-CAPS"></a>G_LOG_2_BASE_10</h3><a class="indexterm" name="id2993126"></a><pre class="programlisting">#define G_LOG_2_BASE_10		(0.30102999566398119521)
</pre><p>
Used for fooling around with float formats, see 
<a href="http://cch.loria.fr/documentation/IEEE754/numerical_comp_guide/ncg_math.doc.html" target="_top">http://cch.loria.fr/documentation/IEEE754/numerical_comp_guide/ncg_math.doc.html</a>
</p></div></div><div class="refsect1" lang="en"><a name="id2993152"></a><h2>See Also</h2><p>
<a href="http://cch.loria.fr/documentation/IEEE754/numerical_comp_guide/ncg_math.doc.html" target="_top">http://cch.loria.fr/documentation/IEEE754/numerical_comp_guide/ncg_math.doc.html</a>
</p></div></div><table class="navigation" width="100%" summary="Navigation footer" cellpadding="2" cellspacing="0"><tr valign="middle"><td align="left"><a accesskey="p" href="glib-Byte-Order-Macros.html"><b>&lt;&lt; Byte Order Macros</b></a></td><td align="right"><a accesskey="n" href="glib-Miscellaneous-Macros.html"><b>Miscellaneous Macros &gt;&gt;</b></a></td></tr></table></body></html>