<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="../../../style.css">
<title>
Gambas Documentation - Float
</title>
</head>
<table class="none" width="100%" cellpadding="0" cellspacing="0" border="0">
<tr><td align="left">
<font size="-1">
<a href="../../../help+en"><img class="flag" alt="Home" border="0" src="../../../img/lang/en.png" align="center"></a>&nbsp;
<a href="../type+en">Up</a>&nbsp;
<a href="date+en">Previous</a>&nbsp;
<a href="integer+en">Next</a>&nbsp;
</td></tr></table>
<div class="notab">
<h1>
Float
</h1>
<div class="black"><font size="-2"><b>Syntax</b></font></div>
<pre class="syntax"><b>DIM</b> Var <b>AS</b> <b>Float</b></pre><p>

This native datatype represents a double floating point value, i.e. a eight bytes floating point value.
<p>
The value of a Float is a number between -8.98846567431105E+307 and +8.98846567431105E+307
<p>
The precision of Float is 52 binary digits, which is 16 decimale digits (2^-52).
This means: if add to 1.0 a (positive) number which is less than 2E-16 than the result will be exaclty 1.0
<p>

<div class="gray"><font size="-2"><b>Example</b></font></div>
<pre class="example">PUBLIC x AS Float

PUBLIC SUB ButFloat_Click()
DIM y AS Float

x = Sin(0.32)
y = x - (0.32 - 0.32 ^ 3 / (2 * 3))
END
<hr>
0.314566560616	2.789394945107E-5</pre>
<p>
<div class="warning"><table class="none" border="0"><tr><td width="40" valign="top"><img border="0" src="../../../img/warning.png" align="center"></td><td valign="top">
Overflow during Float arithmetic operations is not detected!
Instead the result is set to <i>1E+2147483647</i> resp <i>-1E+2147483647</i>
<p>
If such an overflowed number is used in further expressions, then the execution stops and a message window shows &quot;Mathematic error&quot;. But the value of a Float can be compared against maxfloat or minfloat.
</td></tr></table></div>
<p>
<div class="gray"><font size="-2"><b>Example</b></font></div>
<pre class="example">CONST maxfloat AS Float = +8.98846567431105E+307
CONST minfloat AS Float = -8.98846567431105E+307
...
IF y &gt; maxfloat OR y &lt; minfloat THEN
  PRINT &quot;Float y overflow&quot;
ELSE
  x = y / 23000
ENDIF</pre>
<p>
<hr><b>See also</b><br>
<a href="../type+en">Datatypes</a>&nbsp; <a href="../../cat/arith+en">Arithmetical Functions</a>&nbsp; <a href="../../cat/trigo+en">Trigonometric Functions</a>&nbsp; <a href="../../cat/exp+en">Logarithms &amp; Exponentials Functions</a>&nbsp;

</div>
</body>
</html>

