| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
<html> |
| 17 |
<head> |
| 18 |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
| 19 |
<meta http-equiv="Content-Language" content="en-us"> |
| 20 |
<title>float</title> |
| 21 |
</head> |
| 22 |
<body bgcolor="#DAD3C5" vlink="#0094D2" link="#003258"> |
| 23 |
<table align="left" border="0" cellspacing="0" cellpadding="0" valign=top> |
| 24 |
<tr> |
| 25 |
<td width=105 height=40><a href="https://projects.eclipse.org/projects/tools.titan"><img src="../images/titan_transparent.gif" border=0 width=105 height=40 align="left" alt="Titan"></a></td> |
| 26 |
</tr> |
| 27 |
</table> |
| 28 |
<table border="0" align="right" cellpadding="0" cellspacing="0"> |
| 29 |
<tr> |
| 30 |
<td><a href="../titan_main.html" alt="contents"><img border="0" src="../images/ao.jpg" width="53" height="40"></a></td> |
| 31 |
<td><a href="../titan_index.html" alt="index"><img border="0" src="../images/up.jpg" width="53" height="40"></a></td> |
| 32 |
<td><a alt="previous" href="false.html"><img border="0" src="../images/left.jpg" width="53" height="40"></a></td> |
| 33 |
<td><a href="float2int.html" alt="next"><img border="0" src="../images/right.jpg" width="53" height="40"></a></td> |
| 34 |
</tr> |
| 35 |
</table> |
| 36 |
<p><br clear="all"> |
| 37 |
</p> |
| 38 |
<hr> |
| 39 |
<h1>float</h1> |
| 40 |
<hr align="left" width="75%"> |
| 41 |
<p>The keyword <b><font face="Courier New">float</font></b> denotes a simple basic type describing floating point numbers.</p> |
| 42 |
<ul> |
| 43 |
<li>Values of float type shall be denoted by either |
| 44 |
<ul> |
| 45 |
<li>the <a href="#double_quotation">normal notation</a> with a dot in a sequence of numbers, or</li> |
| 46 |
<li>by <a href="#Example 2">two numbers separated by E</a> where the first number specifies the mantissa and the second specifies the exponent (the base is always 10).</li> |
| 47 |
</ul> |
| 48 |
</li> |
| 49 |
<li>The <a href="#quotation_inside">range of the permitted floating point values</a> may be specified.</li> |
| 50 |
<li>The specified <a href="infinity.html#quotation_inside">range may be infinite</a> (both positive and negative; see the keyword <a href="infinity.html"><b><font |
| 51 |
face="Courier New" color="#003258" size="4">infinity</font></b></a>).</li> |
| 52 |
<li>Another way to limit the permitted float values is <a href="#list">to list them</a>.</li> |
| 53 |
<li>Value list and value range restrictions <a href="#relation">may be combined</a></li> |
| 54 |
<li>A <a href="#Example 5">random floating point number</a> may be generated using the predefined function rnd().</li> |
| 55 |
<li>Predefined function operating on floating point numbers:</li> |
| 56 |
<ul> |
| 57 |
<li><a href="#str2int">float2int</a> converts a floating point number into an integer value.</li> |
| 58 |
</ul> |
| 59 |
</ul> |
| 60 |
<table border="0" width="100%" bgcolor="#C9C2BB" cellpadding="4"> |
| 61 |
<tr> |
| 62 |
<td width="100%"> |
| 63 |
<p> <u>TITAN specific extension to the standard:</u></p> |
| 64 |
<ul> |
| 65 |
<ul> |
| 66 |
<li><a href="#str2bit">float2str</a> converts a floating point value to a character string.</li> |
| 67 |
</ul> |
| 68 |
</ul> |
| 69 |
</td> |
| 70 |
</tr> |
| 71 |
</table> |
| 72 |
<p>Related keyword:</p> |
| 73 |
<ul> |
| 74 |
<li><a href="float2int.html"><b><font face="Courier New" color="#003258" size="4">float2int</font></b></a></li> |
| 75 |
<li><a href="float2str.html"><b><font face="Courier New" color="#003258" size="4">float2str</font></b></a></li> |
| 76 |
<li><a href="infinity.html"><b><font face="Courier New" color="#003258" size="4">infinity</font></b></a></li> |
| 77 |
<li><a href="int2float.html"><b><font face="Courier New" color="#003258" size="4">int2float</font></b></a></li> |
| 78 |
<li><a href="rnd.html"><b><font face="Courier New" color="#003258" size="4">rnd</font></b></a></li> |
| 79 |
<li><a href="str2float.html"><b><font face="Courier New" color="#003258" size="4">str2float</font></b></a></li> |
| 80 |
</ul> |
| 81 |
<hr align="left" width="50%"> |
| 82 |
<div align="center"> |
| 83 |
<center> |
| 84 |
<table border="0" width="90%" bgcolor="#FFB599" cellpadding="4"> |
| 85 |
<tr> |
| 86 |
<td width="100%"> |
| 87 |
<h3 align="center"><font face="Courier New" color="#003258" size="5"><b>float</b></font></h3> |
| 88 |
</td> |
| 89 |
</tr> |
| 90 |
</table> |
| 91 |
</center> |
| 92 |
</div> |
| 93 |
<hr align="left" width="50%"> |
| 94 |
<p><a name="double_quotation">Example 1</a>: |
| 95 |
<p><font face="Courier New">var float v_lebeg := 65.213;<br> |
| 96 |
</font> |
| 97 |
<p>The variable defined is called v_lebeg and has the initial value 65.213 (with scientific notation 6.5213E1).</p> |
| 98 |
<hr align="left" width="50%"> |
| 99 |
<p><a name="Example 2">Example 2</a>:</p> |
| 100 |
<p><font face="Courier New">var float v_flotte := 6521.3E-2;<br> |
| 101 |
</font> |
| 102 |
<p>The variable defined is called v_flotte and has the initial value 6521.3E-2 (with normal notation 65.213).</p> |
| 103 |
<hr align="left" width="50%"> |
| 104 |
<p><a name="quotation_inside">Example 2</a>: |
| 105 |
<p><font face="Courier New">var float v_territoire (3.3 .. 7.7);<br> |
| 106 |
</font> |
| 107 |
<p>The variable v_territoire may have values between 3.3 and 7.7 inclusive.</p> |
| 108 |
<hr align="left" width="50%"> |
| 109 |
<p><a name="list">Example 3</a>: |
| 110 |
<p><font face="Courier New">var float v_kado (1.2, 5E9, -12);<br> |
| 111 |
</font> |
| 112 |
<p>The variable called v_kado may hold the values 1.2, 5E9 and -12 only .</p> |
| 113 |
<hr align="left" width="50%"> |
| 114 |
<p><a name="relation">Example 4</a>: |
| 115 |
<p><font face="Courier New">var float v_kenyeer ( 1.9, 7.000 .. 7.999, 11.1E1 );<br> |
| 116 |
</font> |
| 117 |
<p>The variable v_kenyeer may hold the values 1.9, 111 and any value between 7.000 and 7.999 inclusive.</p> |
| 118 |
<hr align="left" width="50%"> |
| 119 |
<p><a name="Example 5">Example 5</a>:</p> |
| 120 |
<p><font face="Courier New">var float v_veeletlen := rnd ( 1.9 );<br> |
| 121 |
</font> |
| 122 |
<p>The variable v_veeletlen will have a random initial value between 0 and 1. The argument of the function is an optional seed value used for the first time random value calculation. If it is |
| 123 |
omitted, the system time will be used as seed.</p> |
| 124 |
<hr align="left" width="50%"> |
| 125 |
<p><a name="str2int">Example 6</a>: |
| 126 |
<p><font face="Courier New">const integer c_tam := float2int (344.511E-2);<br> |
| 127 |
</font> |
| 128 |
<p>The constant called c_tam will have the integer value 3 (the function calculates the integer value by removing the fractional part of the argument).</p> |
| 129 |
<hr align="left" width="50%"> |
| 130 |
<p><a name="str2bit">Example 7</a>:</p> |
| 131 |
<p><font face="Courier New">const bitstring c_recefice := float2str (3.14); <br> |
| 132 |
</font> |
| 133 |
<p>The constant called c_recefice will contain the character string "3.140000" because if the input is zero or its absolute value is between 10<sup>-4</sup> and 10<sup>10</sup> the |
| 134 |
decimal dot notation is used in the output with 6 digits in the fraction part. Otherwise the exponential notation is used with automatic (at most 6) digits precision in the mantissa.</p> |
| 135 |
<hr align="left" width="25%"> |
| 136 |
<hr align="left" width="25%"> |
| 137 |
<p align="left"><a HREF="BNF.html#floatkeyword">BNF definition</a> of <font face="Courier New">float</font><br> |
| 138 |
<a HREF="BNF.html#floatvalue">BNF definition</a> of float value</p> |
| 139 |
</body> |
| 140 |
</html> |