Literals/Floating point: Difference between revisions
Content deleted Content added
Puppydrum64 (talk | contribs) |
Thundergnat (talk | contribs) m syntax highlighting fixup automation |
||
Line 16: | Line 16: | ||
=={{header|11l}}== |
=={{header|11l}}== |
||
< |
<syntaxhighlight lang="11l">// 64-bit floating point literals: |
||
2.3 |
2.3 |
||
0.3e+34 |
0.3e+34 |
||
Line 22: | Line 22: | ||
// single precision (32-bit) floating point literals: |
// single precision (32-bit) floating point literals: |
||
2.3s |
2.3s |
||
0.3e+34s</ |
0.3e+34s</syntaxhighlight> |
||
=={{header|360 Assembly}}== |
=={{header|360 Assembly}}== |
||
[[wp:IBM_hexadecimal_floating_point|IBM hexadecimal floating point]] |
[[wp:IBM_hexadecimal_floating_point|IBM hexadecimal floating point]] |
||
< |
<syntaxhighlight lang="360asm">XS4 DC E'1.23456E-4' short floating-point |
||
XDPI DC D'3.141592653589793' long floating-point |
XDPI DC D'3.141592653589793' long floating-point |
||
Line 40: | Line 40: | ||
* extended floating-point - 128 bits - 16 bytes : 33 decimal digits |
* extended floating-point - 128 bits - 16 bytes : 33 decimal digits |
||
* absolute approximate range: 5e-79 to 7e75 </ |
* absolute approximate range: 5e-79 to 7e75 </syntaxhighlight> |
||
=={{header|6502 Assembly}}== |
=={{header|6502 Assembly}}== |
||
You'll have to do it the hard way unfortunately. I used an IEEE-754 floating point calculator to figure this out. |
You'll have to do it the hard way unfortunately. I used an IEEE-754 floating point calculator to figure this out. |
||
< |
<syntaxhighlight lang="6502asm">byte $DB,$0F,$49,$40 ;3.141592654</syntaxhighlight> |
||
=={{header|68000 Assembly}}== |
=={{header|68000 Assembly}}== |
||
If you don't have a floating-point unit, floats aren't of very much use. The most portable way to declare float literals is also the most tedious: by storing their hexadecimal representation as data. |
If you don't have a floating-point unit, floats aren't of very much use. The most portable way to declare float literals is also the most tedious: by storing their hexadecimal representation as data. |
||
< |
<syntaxhighlight lang="68000devpac">Pi: |
||
DC.L $40490FDB</ |
DC.L $40490FDB</syntaxhighlight> |
||
=={{header|Ada}}== |
=={{header|Ada}}== |
||
Real literals contain decimal point. The exponent part is optional. Underline may be used to separate groups of digits. A literal does not have sign, + or - are unary operations. Examples of real literals: |
Real literals contain decimal point. The exponent part is optional. Underline may be used to separate groups of digits. A literal does not have sign, + or - are unary operations. Examples of real literals: |
||
<syntaxhighlight lang="ada"> |
|||
<lang Ada> |
|||
3.141_592_6 |
3.141_592_6 |
||
1.0E-12 |
1.0E-12 |
||
0.13 |
0.13 |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Aime}}== |
=={{header|Aime}}== |
||
< |
<syntaxhighlight lang="aime">3.14 |
||
5.0 |
5.0 |
||
8r # without the "r"(eal) suffix, "8" would be an integer |
8r # without the "r"(eal) suffix, "8" would be an integer |
||
.125</ |
.125</syntaxhighlight> |
||
=={{header|ALGOL 68}}== |
=={{header|ALGOL 68}}== |
||
< |
<syntaxhighlight lang="algol68"># floating point literals are called REAL denotations in Algol 68 # |
||
# They have the following forms: # |
# They have the following forms: # |
||
# 1: a digit sequence followed by "." followed by a digit sequence # |
# 1: a digit sequence followed by "." followed by a digit sequence # |
||
Line 90: | Line 90: | ||
r := 3.142e-23; |
r := 3.142e-23; |
||
r := 1 234 567 . 9 e - 4; |
r := 1 234 567 . 9 e - 4; |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|ALGOL W}}== |
=={{header|ALGOL W}}== |
||
< |
<syntaxhighlight lang="algolw">begin |
||
real r; long real lr; |
real r; long real lr; |
||
% floating point literals have the following forms: % |
% floating point literals have the following forms: % |
||
Line 116: | Line 116: | ||
r := 7; |
r := 7; |
||
lr := 5.4321L; |
lr := 5.4321L; |
||
end.</ |
end.</syntaxhighlight> |
||
=={{header|Applesoft BASIC}}== |
=={{header|Applesoft BASIC}}== |
||
Line 134: | Line 134: | ||
=={{header|Arturo}}== |
=={{header|Arturo}}== |
||
< |
<syntaxhighlight lang="rebol">pi: 3.14 |
||
print [pi "->" type pi]</ |
print [pi "->" type pi]</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 144: | Line 144: | ||
With the One True Awk ([[nawk]]), all numbers are floating-point. A numeric literal consists of one or more digits '0-9', with an optional decimal point '.', followed by an optional exponent. The exponent is a letter 'E' or 'e', then an optional '+' or '-' sign, then one or more digits '0-9'. |
With the One True Awk ([[nawk]]), all numbers are floating-point. A numeric literal consists of one or more digits '0-9', with an optional decimal point '.', followed by an optional exponent. The exponent is a letter 'E' or 'e', then an optional '+' or '-' sign, then one or more digits '0-9'. |
||
< |
<syntaxhighlight lang="awk">2 |
||
2. |
2. |
||
.3 |
.3 |
||
Line 150: | Line 150: | ||
45e+6 |
45e+6 |
||
78e-9 |
78e-9 |
||
1.2E34</ |
1.2E34</syntaxhighlight> |
||
Other implementations of Awk can differ. They might not use floating-point numbers for integers. |
Other implementations of Awk can differ. They might not use floating-point numbers for integers. |
||
Line 156: | Line 156: | ||
This Awk program will detect whether each line of input contains a valid integer. |
This Awk program will detect whether each line of input contains a valid integer. |
||
< |
<syntaxhighlight lang="awk">/^([0-9]+(\.[0-9]*)?|\.[0-9]+)([Ee][-+]?[0-9]+)?$/ { |
||
print $0 " is a literal number." |
print $0 " is a literal number." |
||
next |
next |
||
Line 163: | Line 163: | ||
{ |
{ |
||
print $0 " is not valid." |
print $0 " is not valid." |
||
}</ |
}</syntaxhighlight> |
||
A leading plus or minus sign (as in <tt>+23</tt> or <tt>-14</tt>) is not part of the literal; it is a unary operator. This is easy to check if you know that exponentiation has a higher precedence than unary minus; <tt>-14 ** 2</tt> acts like <tt>-(14 ** 2)</tt>, not like <tt>(-14) ** 2</tt>. |
A leading plus or minus sign (as in <tt>+23</tt> or <tt>-14</tt>) is not part of the literal; it is a unary operator. This is easy to check if you know that exponentiation has a higher precedence than unary minus; <tt>-14 ** 2</tt> acts like <tt>-(14 ** 2)</tt>, not like <tt>(-14) ** 2</tt>. |
||
Line 169: | Line 169: | ||
=={{header|Axe}}== |
=={{header|Axe}}== |
||
Axe does not support floating point literals. However, it does support converting floats to integers and vice versa. |
Axe does not support floating point literals. However, it does support converting floats to integers and vice versa. |
||
< |
<syntaxhighlight lang="axe">123→float{L₁} |
||
float{L₁}→I</ |
float{L₁}→I</syntaxhighlight> |
||
Axe does, however, support fixed-point literals. |
Axe does, however, support fixed-point literals. |
||
<lang |
<syntaxhighlight lang="axe">12.25→A</syntaxhighlight> |
||
There are some mathematical operators in Axe that operate specifically on fixed-point numbers. |
There are some mathematical operators in Axe that operate specifically on fixed-point numbers. |
||
=={{header|BBC BASIC}}== |
=={{header|BBC BASIC}}== |
||
< |
<syntaxhighlight lang="bbcbasic"> REM Floating-point literal syntax: |
||
REM [-]{digit}[.]{digit}[E[-]{digit}] |
REM [-]{digit}[.]{digit}[E[-]{digit}] |
||
Line 190: | Line 190: | ||
PRINT 8.9E |
PRINT 8.9E |
||
PRINT .33E- |
PRINT .33E- |
||
PRINT -.</ |
PRINT -.</syntaxhighlight> |
||
'''Output:''' |
'''Output:''' |
||
<pre> |
<pre> |
||
Line 217: | Line 217: | ||
=={{header|C sharp}}== |
=={{header|C sharp}}== |
||
Floating point suffixes are not case-sensitive. |
Floating point suffixes are not case-sensitive. |
||
< |
<syntaxhighlight lang="csharp">double d = 1; |
||
d = 1d; |
d = 1d; |
||
d = 1D; |
d = 1D; |
||
Line 241: | Line 241: | ||
m = 12e-12m; |
m = 12e-12m; |
||
m = 12E-12m; |
m = 12E-12m; |
||
m = 1_234e-1_2m;</ |
m = 1_234e-1_2m;</syntaxhighlight> |
||
=={{header|C++}}== |
=={{header|C++}}== |
||
< |
<syntaxhighlight lang="cpp">#include <iostream> |
||
int main() |
int main() |
||
Line 273: | Line 273: | ||
std::cout << "\nfloat3: " << float3; |
std::cout << "\nfloat3: " << float3; |
||
std::cout << "\n"; |
std::cout << "\n"; |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 356: | Line 356: | ||
Dyalect built-in types include only one floating point number of type ''Float'' (64-bit). Both regular and scientific notations are supported: |
Dyalect built-in types include only one floating point number of type ''Float'' (64-bit). Both regular and scientific notations are supported: |
||
< |
<syntaxhighlight lang="dyalect">var x = 42.02 |
||
var y = 0.174e-17</ |
var y = 0.174e-17</syntaxhighlight> |
||
EBNF grammar for the floating point number is as follows: |
EBNF grammar for the floating point number is as follows: |
||
Line 371: | Line 371: | ||
Floating point literals are of the form D.DeSD, where D represents a sequence of decimal digits, and S represents an optional sign. A leading "+" or "-" indicates a unary plus or minus feature and is not considered part of the literal. |
Floating point literals are of the form D.DeSD, where D represents a sequence of decimal digits, and S represents an optional sign. A leading "+" or "-" indicates a unary plus or minus feature and is not considered part of the literal. |
||
'''Examples:'''< |
'''Examples:'''<syntaxhighlight lang="eiffel"> |
||
1. |
1. |
||
1.23 |
1.23 |
||
Line 377: | Line 377: | ||
.5 |
.5 |
||
1.23E4 |
1.23E4 |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Elena}}== |
=={{header|Elena}}== |
||
< |
<syntaxhighlight lang="elena">real r := 1; |
||
r := 23.2r; |
r := 23.2r; |
||
r := 1.2e+11r;</ |
r := 1.2e+11r;</syntaxhighlight> |
||
=={{header|Elixir}}== |
=={{header|Elixir}}== |
||
< |
<syntaxhighlight lang="elixir">iex(180)> 0.123 |
||
0.123 |
0.123 |
||
iex(181)> -123.4 |
iex(181)> -123.4 |
||
Line 404: | Line 404: | ||
iex(187)> 1e4 |
iex(187)> 1e4 |
||
** (SyntaxError) iex:187: syntax error before: e4</ |
** (SyntaxError) iex:187: syntax error before: e4</syntaxhighlight> |
||
=={{header|Erlang}}== |
=={{header|Erlang}}== |
||
Line 410: | Line 410: | ||
=={{header|Euphoria}}== |
=={{header|Euphoria}}== |
||
< |
<syntaxhighlight lang="euphoria"> |
||
printf(1,"Exponential:\t%e, %e, %e, %e\n",{-10.1246,10.2356,16.123456789,64.12}) |
printf(1,"Exponential:\t%e, %e, %e, %e\n",{-10.1246,10.2356,16.123456789,64.12}) |
||
printf(1,"Floating Point\t%03.3f, %04.3f, %+3.3f, %3.3f\n",{-10.1246,10.2356,16.123456789,64.12}) |
printf(1,"Floating Point\t%03.3f, %04.3f, %+3.3f, %3.3f\n",{-10.1246,10.2356,16.123456789,64.12}) |
||
printf(1,"Floating Point or Exponential: %g, %g, %g, %g\n",{10,16.123456789,64,123456789.123}) |
printf(1,"Floating Point or Exponential: %g, %g, %g, %g\n",{10,16.123456789,64,123456789.123}) |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 423: | Line 423: | ||
=={{header|Factor}}== |
=={{header|Factor}}== |
||
< |
<syntaxhighlight lang="factor">3.14 ! basic float |
||
+3.14 ! Optional signs |
+3.14 ! Optional signs |
||
-3.14 |
-3.14 |
||
Line 449: | Line 449: | ||
! normalized hex form ±0x1.MMMMMMMMMMMMMp±EEEE allows any floating-point |
! normalized hex form ±0x1.MMMMMMMMMMMMMp±EEEE allows any floating-point |
||
! number to be specified precisely according to IEEE 754 representation |
! number to be specified precisely according to IEEE 754 representation |
||
+0x1.1234567891234p+0002 ! 4.28444444440952</ |
+0x1.1234567891234p+0002 ! 4.28444444440952</syntaxhighlight> |
||
=={{header|Fennel}}== |
=={{header|Fennel}}== |
||
< |
<syntaxhighlight lang="fennel">;;Numeric literals with a decimal component are treated as floating point. |
||
3.14159 ;3.14159 |
3.14159 ;3.14159 |
||
Line 464: | Line 464: | ||
;;Underscores can optionally be used to split numbers into readable chunks. |
;;Underscores can optionally be used to split numbers into readable chunks. |
||
123_456.789 ;123456.789 |
123_456.789 ;123456.789 |
||
0x1234_5678.9a ;305419896.60156</ |
0x1234_5678.9a ;305419896.60156</syntaxhighlight> |
||
=={{header|Forth}}== |
=={{header|Forth}}== |
||
Line 515: | Line 515: | ||
Some examples, taken from the language documentation follow: |
Some examples, taken from the language documentation follow: |
||
< |
<syntaxhighlight lang="freebasic">' FB 1.05.0 Win64 (default dialect) |
||
Dim a As Double = 123.456 |
Dim a As Double = 123.456 |
||
Line 528: | Line 528: | ||
Dim j As Single = -123.456e-7f |
Dim j As Single = -123.456e-7f |
||
Dim k As Double = 0# |
Dim k As Double = 0# |
||
Dim l As Double = 3.141592653589e3#</ |
Dim l As Double = 3.141592653589e3#</syntaxhighlight> |
||
=={{header|GAP}}== |
=={{header|GAP}}== |
||
< |
<syntaxhighlight lang="gap">-3.14 |
||
22.03e4 |
22.03e4 |
||
4.54e-5</ |
4.54e-5</syntaxhighlight> |
||
=={{header|gecho}}== |
=={{header|gecho}}== |
||
< |
<syntaxhighlight lang="gecho"> |
||
0.0 |
0.0 |
||
-1 |
-1 |
||
Line 543: | Line 543: | ||
-1.4324 |
-1.4324 |
||
3 4 / |
3 4 / |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Go}}== |
=={{header|Go}}== |
||
Line 556: | Line 556: | ||
=={{header|Groovy}}== |
=={{header|Groovy}}== |
||
Solution: |
Solution: |
||
< |
<syntaxhighlight lang="groovy">println 1.00f // float (IEEE-32) |
||
println 1.00d // double (IEEE-64) |
println 1.00d // double (IEEE-64) |
||
println 1.00 // BigDecimal (scaled BigInteger) |
println 1.00 // BigDecimal (scaled BigInteger) |
||
Line 566: | Line 566: | ||
assert 1.00 instanceof BigDecimal |
assert 1.00 instanceof BigDecimal |
||
assert 1.00g instanceof BigDecimal |
assert 1.00g instanceof BigDecimal |
||
assert 1.00e0 instanceof BigDecimal</ |
assert 1.00e0 instanceof BigDecimal</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 578: | Line 578: | ||
Haskell supports decimal representation of float literals, with or without an exponent. For more information, see the [http://www.haskell.org/onlinereport/lexemes.html#sect2.5 relevant portion] of the Haskell 98 Report. |
Haskell supports decimal representation of float literals, with or without an exponent. For more information, see the [http://www.haskell.org/onlinereport/lexemes.html#sect2.5 relevant portion] of the Haskell 98 Report. |
||
< |
<syntaxhighlight lang="haskell">main = print [0.1,23.3,35e-1,56E+2,14.67e1] |
||
</syntaxhighlight> |
|||
</lang> |
|||
Output: |
Output: |
||
Line 588: | Line 588: | ||
The program below shows a full range of valid real literals. |
The program below shows a full range of valid real literals. |
||
< |
<syntaxhighlight lang="icon">procedure main() |
||
every write( ![ 1., .1, 0.1, 2e10, 2E10, 3e-1, .4e2, 1.41e2, 8.e+3, 3.141e43 ]) |
every write( ![ 1., .1, 0.1, 2e10, 2E10, 3e-1, .4e2, 1.41e2, 8.e+3, 3.141e43 ]) |
||
end</ |
end</syntaxhighlight> |
||
The function write will cause the real values to be coerced as string constants. Icon/Unicon will format these as it sees fit resorting to exponent forms only where needed. |
The function write will cause the real values to be coerced as string constants. Icon/Unicon will format these as it sees fit resorting to exponent forms only where needed. |
||
Line 604: | Line 604: | ||
Here is an informal bnf for J's numeric constant language. Note, however, that the implementation may disallow some unusual cases -- cases which are not treated as exceptional here (for example, the [http://jsoftware.com/help/dictionary/dcons.htm language specification] allows 1.2e3.4 but the current implementation does not support fractional powers of 10 in numeric constants): |
Here is an informal bnf for J's numeric constant language. Note, however, that the implementation may disallow some unusual cases -- cases which are not treated as exceptional here (for example, the [http://jsoftware.com/help/dictionary/dcons.htm language specification] allows 1.2e3.4 but the current implementation does not support fractional powers of 10 in numeric constants): |
||
< |
<syntaxhighlight lang="bnf">numeric-constant ::= number-constant | number-constant whitespace numeric-constant |
||
whitespace ::= whitespacecharacter | whitespacecharacter whitespace |
whitespace ::= whitespacecharacter | whitespacecharacter whitespace |
||
whitespacecharacter ::= ' ' | TAB |
whitespacecharacter ::= ' ' | TAB |
||
Line 626: | Line 626: | ||
signed-digits ::= digits | '_' digits |
signed-digits ::= digits | '_' digits |
||
digits ::= digit | digit digits |
digits ::= digit | digit digits |
||
digit ::= '0'|'1'|'2'|'3'|'4'|'5'|'6'|'7'|'8'|'9'</ |
digit ::= '0'|'1'|'2'|'3'|'4'|'5'|'6'|'7'|'8'|'9'</syntaxhighlight> |
||
e indicates exponential or scientific notation (number on left multiplied by 10 raised to power indicated by number on right) |
e indicates exponential or scientific notation (number on left multiplied by 10 raised to power indicated by number on right) |
||
Line 640: | Line 640: | ||
Floating point examples: |
Floating point examples: |
||
< |
<syntaxhighlight lang="j"> 0 1 _2 3.4 3e4 3p4 3x4 |
||
0 1 _2 3.4 30000 292.227 163.794 |
0 1 _2 3.4 30000 292.227 163.794 |
||
16bcafe.babe _16b_cafe.babe _10b11 |
16bcafe.babe _16b_cafe.babe _10b11 |
||
51966.7 46818.7 _9</ |
51966.7 46818.7 _9</syntaxhighlight> |
||
Note that all the values in an array are the same type, thus the 0, 1 and 2 in the above example are floating point because they do not appear by themselves. Note also that by default J displays no more than six significant digits of floating point values. |
Note that all the values in an array are the same type, thus the 0, 1 and 2 in the above example are floating point because they do not appear by themselves. Note also that by default J displays no more than six significant digits of floating point values. |
||
=={{header|Java}}== |
=={{header|Java}}== |
||
< |
<syntaxhighlight lang="java">1. //double equal to 1.0 |
||
1.0 //double |
1.0 //double |
||
2432311.7567374 //double |
2432311.7567374 //double |
||
Line 660: | Line 660: | ||
1.0F //float |
1.0F //float |
||
1 / 2. //double |
1 / 2. //double |
||
1 / 2 //int equal to 0</ |
1 / 2 //int equal to 0</syntaxhighlight> |
||
Values that are outside the bounds of a type will give compiler errors when trying to force them to that type. |
Values that are outside the bounds of a type will give compiler errors when trying to force them to that type. |
||
=={{header|jq}}== |
=={{header|jq}}== |
||
jq floating point literals are identical to JSON floating point literals. However, when jq parses a floating point or integer literal, conversion to IEEE 754 numbers takes place, which may result in a loss of accuracy and/or an apparent change of type, as illustrated by the following sequence of input => output pairs: |
jq floating point literals are identical to JSON floating point literals. However, when jq parses a floating point or integer literal, conversion to IEEE 754 numbers takes place, which may result in a loss of accuracy and/or an apparent change of type, as illustrated by the following sequence of input => output pairs: |
||
< |
<syntaxhighlight lang="sh">1.0 => 1 |
||
1.2 => 1.2 |
1.2 => 1.2 |
||
1e10 => 10000000000 |
1e10 => 10000000000 |
||
Line 671: | Line 671: | ||
1e1234 => 1.7976931348623157e+308 |
1e1234 => 1.7976931348623157e+308 |
||
.1 => 0.1 |
.1 => 0.1 |
||
.1e1 => 1</ |
.1e1 => 1</syntaxhighlight> |
||
=={{header|Julia}}== |
=={{header|Julia}}== |
||
{{works with|Julia|0.6}} |
{{works with|Julia|0.6}} |
||
< |
<syntaxhighlight lang="julia">0.1 |
||
.1 |
.1 |
||
1. |
1. |
||
Line 682: | Line 682: | ||
1e+10 |
1e+10 |
||
1e-10 |
1e-10 |
||
0x01p-1 # hex float</ |
0x01p-1 # hex float</syntaxhighlight> |
||
=={{header|Kotlin}}== |
=={{header|Kotlin}}== |
||
< |
<syntaxhighlight lang="scala">val d: Double = 1.0 |
||
val d2: Double = 1.234e-10 |
val d2: Double = 1.234e-10 |
||
val f: Float = 728832f |
val f: Float = 728832f |
||
val f2: Float = 728832F</ |
val f2: Float = 728832F</syntaxhighlight> |
||
=={{header|Lasso}}== |
=={{header|Lasso}}== |
||
<syntaxhighlight lang="lasso">0.0 |
|||
<lang Lasso>0.0 |
|||
0.1 |
0.1 |
||
-0.1 |
-0.1 |
||
1.2e3 |
1.2e3 |
||
1.3e+3 |
1.3e+3 |
||
1.2e-3</ |
1.2e-3</syntaxhighlight> |
||
=={{header|Lingo}}== |
=={{header|Lingo}}== |
||
< |
<syntaxhighlight lang="lingo">put 0.23 |
||
-- 0.2300 |
-- 0.2300 |
||
Line 721: | Line 721: | ||
-- casting string to float |
-- casting string to float |
||
put float("0.23") |
put float("0.23") |
||
-- 0.23000000</ |
-- 0.23000000</syntaxhighlight> |
||
=={{header|Lua}}== |
=={{header|Lua}}== |
||
< |
<syntaxhighlight lang="lua">3.14159 |
||
314.159E-2</ |
314.159E-2</syntaxhighlight> |
||
=={{header|M2000 Interpreter}}== |
=={{header|M2000 Interpreter}}== |
||
We can use Decimal using @ and Currency using # (no exponent part, both types) |
We can use Decimal using @ and Currency using # (no exponent part, both types) |
||
<syntaxhighlight lang="m2000 interpreter"> |
|||
<lang M2000 Interpreter> |
|||
Def ExpType$(x)=Type$(x) |
Def ExpType$(x)=Type$(x) |
||
Print ExpType$(-12)="Double", -12 |
Print ExpType$(-12)="Double", -12 |
||
Line 740: | Line 740: | ||
Print ExpType$(12.e-5~)="Single", 12.e-5~ |
Print ExpType$(12.e-5~)="Single", 12.e-5~ |
||
Print ExpType$(.1~)="Single", .1~ |
Print ExpType$(.1~)="Single", .1~ |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Maple}}== |
=={{header|Maple}}== |
||
Maple distinguishes "software floats" (of arbitrary precision) and "hardware floats" (of machine precision). To get the latter, use the "HFloat" constructor. |
Maple distinguishes "software floats" (of arbitrary precision) and "hardware floats" (of machine precision). To get the latter, use the "HFloat" constructor. |
||
<syntaxhighlight lang="maple"> |
|||
<lang Maple> |
|||
> 123.456; # decimal notation |
> 123.456; # decimal notation |
||
123.456 |
123.456 |
||
Line 793: | Line 793: | ||
> Float(undefined); # "NaN", not-a-number |
> Float(undefined); # "NaN", not-a-number |
||
Float(undefined) |
Float(undefined) |
||
</syntaxhighlight> |
|||
</lang> |
|||
Whether a given float is a software or hardware float can be determined by using "type". |
Whether a given float is a software or hardware float can be determined by using "type". |
||
<syntaxhighlight lang="maple"> |
|||
<lang Maple> |
|||
> type( 2.3, 'hfloat' ); |
> type( 2.3, 'hfloat' ); |
||
false |
false |
||
Line 801: | Line 801: | ||
> type( HFloat( 2.3 ), 'hfloat' ); |
> type( HFloat( 2.3 ), 'hfloat' ); |
||
true |
true |
||
</syntaxhighlight> |
|||
</lang> |
|||
(There is also a type "sfloat" for software floats, and the type "float", which covers both.) |
(There is also a type "sfloat" for software floats, and the type "float", which covers both.) |
||
=={{header|Mathematica}}/{{header|Wolfram Language}}== |
=={{header|Mathematica}}/{{header|Wolfram Language}}== |
||
< |
<syntaxhighlight lang="mathematica">These numbers are given in the default output format. Large numbers are given in scientific notation. |
||
{6.7^-4,6.7^6,6.7^8} |
{6.7^-4,6.7^6,6.7^8} |
||
{0.00049625,90458.4,4.06068*10^6} |
{0.00049625,90458.4,4.06068*10^6} |
||
Line 819: | Line 819: | ||
In accounting form, negative numbers are given in parentheses, and scientific notation is never used. |
In accounting form, negative numbers are given in parentheses, and scientific notation is never used. |
||
AccountingForm[{5.6,-6.7,10.^7}] |
AccountingForm[{5.6,-6.7,10.^7}] |
||
{5.6,(6.7),10000000.}</ |
{5.6,(6.7),10000000.}</syntaxhighlight> |
||
=={{header|Maxima}}== |
=={{header|Maxima}}== |
||
< |
<syntaxhighlight lang="maxima">/* Maxima has machine floating point (usually double precision IEEE 754), and |
||
arbitrary length "big floats" */ |
arbitrary length "big floats" */ |
||
Line 841: | Line 841: | ||
bfloat(%pi); |
bfloat(%pi); |
||
3.141592653589793238462643383279502884197b0</ |
3.141592653589793238462643383279502884197b0</syntaxhighlight> |
||
=={{header|MIPS Assembly}}== |
=={{header|MIPS Assembly}}== |
||
Ultimately it depends on the assembler, however, it's standard to allow simple expressions like "2.5". Since MIPS uses a floating-point coprocessor with separate registers, the assembler understands that you're trying to load a float into the register rather than an integer, and so the assembler will calculate the IEEE-754 hexadecimal representation for you. |
Ultimately it depends on the assembler, however, it's standard to allow simple expressions like "2.5". Since MIPS uses a floating-point coprocessor with separate registers, the assembler understands that you're trying to load a float into the register rather than an integer, and so the assembler will calculate the IEEE-754 hexadecimal representation for you. |
||
< |
<syntaxhighlight lang="mips">li.s f0,2.5 ;loads the single-precision float 2.5 (0x40200000) into register f0</syntaxhighlight> |
||
Defining literal float data in your code also depends on the assembler. If all else fails, you can use a calculator to get the IEEE-754 hexadecimal representation of the desired float and store it as an "integer." |
Defining literal float data in your code also depends on the assembler. If all else fails, you can use a calculator to get the IEEE-754 hexadecimal representation of the desired float and store it as an "integer." |
||
< |
<syntaxhighlight lang="mips">la $t0,pi |
||
lwc1 $f0,0($t0) ;load pi into $f0 |
lwc1 $f0,0($t0) ;load pi into $f0 |
||
Line 856: | Line 856: | ||
pi: |
pi: |
||
.word 0x40490FDB ;IEEE-754 representation of 3.1415927</ |
.word 0x40490FDB ;IEEE-754 representation of 3.1415927</syntaxhighlight> |
||
=={{header|Nemerle}}== |
=={{header|Nemerle}}== |
||
Line 899: | Line 899: | ||
it's built in ''Rexx'' object and any other Java object that supports floating point numbers. |
it's built in ''Rexx'' object and any other Java object that supports floating point numbers. |
||
< |
<syntaxhighlight lang="netrexx">/* NetRexx */ |
||
options replace format comments java crossref symbols nobinary |
options replace format comments java crossref symbols nobinary |
||
Line 947: | Line 947: | ||
method normalize(fv) private constant |
method normalize(fv) private constant |
||
return fv + 0 |
return fv + 0 |
||
</syntaxhighlight> |
|||
</lang> |
|||
'''Output:''' |
'''Output:''' |
||
<pre> |
<pre> |
||
Line 979: | Line 979: | ||
=={{header|Nim}}== |
=={{header|Nim}}== |
||
< |
<syntaxhighlight lang="nim">var x: float |
||
x = 2.3 |
x = 2.3 |
||
x = 2.0 |
x = 2.0 |
||
Line 991: | Line 991: | ||
var y = 2'f32 # Automatically a float32 |
var y = 2'f32 # Automatically a float32 |
||
var z = 2'f64 # Automatically a float64 |
var z = 2'f64 # Automatically a float64 |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Objeck}}== |
=={{header|Objeck}}== |
||
< |
<syntaxhighlight lang="objeck"> |
||
3 + .14159 |
3 + .14159 |
||
3.14159 |
3.14159 |
||
314.159E-2 |
314.159E-2 |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|OCaml}}== |
=={{header|OCaml}}== |
||
Line 1,008: | Line 1,008: | ||
Here are some examples: |
Here are some examples: |
||
< |
<syntaxhighlight lang="ocaml">0.5 |
||
1.0 |
1.0 |
||
1. (* it is not possible to write only "1" because OCaml is strongly typed, |
1. (* it is not possible to write only "1" because OCaml is strongly typed, |
||
and this would be interpreted as an integer *) |
and this would be interpreted as an integer *) |
||
1e-10 |
1e-10 |
||
3.14159_26535_89793</ |
3.14159_26535_89793</syntaxhighlight> |
||
=={{header|Oforth}}== |
=={{header|Oforth}}== |
||
Line 1,019: | Line 1,019: | ||
A literal floating point number is written with a . and with or without an exponential notation : |
A literal floating point number is written with a . and with or without an exponential notation : |
||
<syntaxhighlight lang="oforth">3.14 |
|||
<lang Oforth>3.14 |
|||
1.0e-12 |
1.0e-12 |
||
0.13 |
0.13 |
||
1000.0 |
1000.0 |
||
.22</ |
.22</syntaxhighlight> |
||
=={{header|PARI/GP}}== |
=={{header|PARI/GP}}== |
||
Line 1,059: | Line 1,059: | ||
=={{header|Perl}}== |
=={{header|Perl}}== |
||
< |
<syntaxhighlight lang="perl"># Standard notations: |
||
.5; |
.5; |
||
0.5; |
0.5; |
||
Line 1,066: | Line 1,066: | ||
# The numbers can be grouped: |
# The numbers can be grouped: |
||
100_000_000; # equals to 100000000 |
100_000_000; # equals to 100000000 |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Phix}}== |
=={{header|Phix}}== |
||
Line 1,080: | Line 1,080: | ||
and on a 64-bit architecture they can range from approximately -1e4932 to +1e4932 with 19 decimal digits.<br> |
and on a 64-bit architecture they can range from approximately -1e4932 to +1e4932 with 19 decimal digits.<br> |
||
The included bigatom library allows working with extremely large integers and floats with arbitrary precision. In the following, '?x' is the Phix shorthand for 'print(1,x)', plus \n |
The included bigatom library allows working with extremely large integers and floats with arbitrary precision. In the following, '?x' is the Phix shorthand for 'print(1,x)', plus \n |
||
<!--< |
<!--<syntaxhighlight lang="phix">--> |
||
<span style="color: #0000FF;">?</span><span style="color: #000000;">1e+12</span> <span style="color: #000080;font-style:italic;">-- (same as 1e12)</span> |
<span style="color: #0000FF;">?</span><span style="color: #000000;">1e+12</span> <span style="color: #000080;font-style:italic;">-- (same as 1e12)</span> |
||
<span style="color: #0000FF;">?</span><span style="color: #000000;">1e-12</span> |
<span style="color: #0000FF;">?</span><span style="color: #000000;">1e-12</span> |
||
Line 1,088: | Line 1,088: | ||
<span style="color: #0000FF;">?</span><span style="color: #000000;">1</span><span style="color: #0000FF;">/</span><span style="color: #000000;">3</span> <span style="color: #000080;font-style:italic;">-- 0.333333</span> |
<span style="color: #0000FF;">?</span><span style="color: #000000;">1</span><span style="color: #0000FF;">/</span><span style="color: #000000;">3</span> <span style="color: #000080;font-style:italic;">-- 0.333333</span> |
||
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%g %G\n"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1e-30</span><span style="color: #0000FF;">)</span> |
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%g %G\n"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1e-30</span><span style="color: #0000FF;">)</span> |
||
<!--</ |
<!--</syntaxhighlight>--> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 1,101: | Line 1,101: | ||
=={{header|PHP}}== |
=={{header|PHP}}== |
||
More [http://php.net/manual/en/language.types.float.php information] about floating point numbers in PHP. |
More [http://php.net/manual/en/language.types.float.php information] about floating point numbers in PHP. |
||
<syntaxhighlight lang="php">.12 |
|||
<lang PHP>.12 |
|||
0.1234 |
0.1234 |
||
1.2e3 |
1.2e3 |
||
7E-10 |
7E-10 |
||
</syntaxhighlight> |
|||
</lang> |
|||
Formal representation: |
Formal representation: |
||
<pre> |
<pre> |
||
Line 1,133: | Line 1,133: | ||
=={{header|PL/I}}== |
=={{header|PL/I}}== |
||
<syntaxhighlight lang="pl/i"> |
|||
<lang PL/I> |
|||
1.2345e-4 decimal floating-point |
1.2345e-4 decimal floating-point |
||
7e5 decimal floating-point |
7e5 decimal floating-point |
||
Line 1,144: | Line 1,144: | ||
or 7.3125 * 2**7 |
or 7.3125 * 2**7 |
||
1e5b binary floating-point equals 1 * 2**5 |
1e5b binary floating-point equals 1 * 2**5 |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|PureBasic}}== |
=={{header|PureBasic}}== |
||
Line 1,155: | Line 1,155: | ||
This is an excerpt of an ANTLR grammar for python obtained from [http://www.antlr.org/grammar/1200715779785/Python.g here]. |
This is an excerpt of an ANTLR grammar for python obtained from [http://www.antlr.org/grammar/1200715779785/Python.g here]. |
||
< |
<syntaxhighlight lang="ebnf">FLOAT |
||
: '.' DIGITS (Exponent)? |
: '.' DIGITS (Exponent)? |
||
| DIGITS '.' Exponent |
| DIGITS '.' Exponent |
||
Line 1,165: | Line 1,165: | ||
Exponent |
Exponent |
||
: ('e' | 'E') ( '+' | '-' )? DIGITS |
: ('e' | 'E') ( '+' | '-' )? DIGITS |
||
;</ |
;</syntaxhighlight> |
||
Examples |
Examples |
||
< |
<syntaxhighlight lang="python"> |
||
2.3 # 2.2999999999999998 |
2.3 # 2.2999999999999998 |
||
.3 # 0.29999999999999999 |
.3 # 0.29999999999999999 |
||
Line 1,175: | Line 1,175: | ||
.3e-34 # 2.9999999999999999e-35 |
.3e-34 # 2.9999999999999999e-35 |
||
2.e34 # 1.9999999999999999e+34 |
2.e34 # 1.9999999999999999e+34 |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Racket}}== |
=={{header|Racket}}== |
||
< |
<syntaxhighlight lang="racket"> |
||
#lang racket |
#lang racket |
||
.2 |
.2 |
||
Line 1,189: | Line 1,189: | ||
2.0f0 ; single float |
2.0f0 ; single float |
||
1.0t0 ; extended 80-bit float (when available on platform) |
1.0t0 ; extended 80-bit float (when available on platform) |
||
</syntaxhighlight> |
|||
</lang> |
|||
Output: |
Output: |
||
Line 1,206: | Line 1,206: | ||
(formerly Perl 6) |
(formerly Perl 6) |
||
Floating point numbers (the Num type) are written in the standard 'e' scientific notation: |
Floating point numbers (the Num type) are written in the standard 'e' scientific notation: |
||
<lang |
<syntaxhighlight lang="raku" line>2e2 # same as 200e0, 2e2, 200.0e0 and 2.0e2 |
||
6.02e23 |
6.02e23 |
||
-2e48 |
-2e48 |
||
1e-9 |
1e-9 |
||
1e0</ |
1e0</syntaxhighlight> |
||
A number like <tt>3.1416</tt> is specifically not floating point, but rational (the Rat type), equivalent to <tt>3927/1250</tt>. On the other hand, <tt>Num(3.1416)</tt> would be considered a floating literal though by virtue of mandatory constant folding. |
A number like <tt>3.1416</tt> is specifically not floating point, but rational (the Rat type), equivalent to <tt>3927/1250</tt>. On the other hand, <tt>Num(3.1416)</tt> would be considered a floating literal though by virtue of mandatory constant folding. |
||
Line 1,216: | Line 1,216: | ||
=={{header|REXX}}== |
=={{header|REXX}}== |
||
All values in REXX are character strings, so a value could hold such things as these (decimal) numbers: |
All values in REXX are character strings, so a value could hold such things as these (decimal) numbers: |
||
< |
<syntaxhighlight lang="rexx">something = 127 |
||
something = '127' /*exactly the same as the above. */ |
something = '127' /*exactly the same as the above. */ |
||
something = 1.27e2 |
something = 1.27e2 |
||
something = 1.27E2 |
something = 1.27E2 |
||
something = 1.27E+2 |
something = 1.27E+2 |
||
something = ' + 0001.27e+00000000000000002 '</ |
something = ' + 0001.27e+00000000000000002 '</syntaxhighlight> |
||
To forcibly express a value in exponential notation, REXX has a built-in function '''format''' that can be used. |
To forcibly express a value in exponential notation, REXX has a built-in function '''format''' that can be used. |
||
Line 1,229: | Line 1,229: | ||
</pre> |
</pre> |
||
by the '''format''' BIF. |
by the '''format''' BIF. |
||
< |
<syntaxhighlight lang="rexx">something = -.00478 |
||
say something |
say something |
||
say format(something,,,,0)</ |
say format(something,,,,0)</syntaxhighlight> |
||
'''output''' |
'''output''' |
||
<pre> |
<pre> |
||
Line 1,249: | Line 1,249: | ||
=={{header|Rust}}== |
=={{header|Rust}}== |
||
The fractional part may be elided (so 1. is valid) but the integer part may not (so .0 is not valid). |
The fractional part may be elided (so 1. is valid) but the integer part may not (so .0 is not valid). |
||
< |
<syntaxhighlight lang="rust">2.3 // Normal floating point literal |
||
3. // Equivalent to 3.0 (3 would be interpreted as an integer) |
3. // Equivalent to 3.0 (3 would be interpreted as an integer) |
||
2f64 // The type (in this case f64, a 64-bit floating point number) may be appended to the value |
2f64 // The type (in this case f64, a 64-bit floating point number) may be appended to the value |
||
1_000.2_f32 // Underscores may appear anywhere in the number for clarity.</ |
1_000.2_f32 // Underscores may appear anywhere in the number for clarity.</syntaxhighlight> |
||
=={{header|Scala}}== |
=={{header|Scala}}== |
||
{{libheader|Scala}} |
{{libheader|Scala}} |
||
As all values in Scala, values are boxed with wrapper classes. The compiler will unbox them to primitive types for run-time execution. |
As all values in Scala, values are boxed with wrapper classes. The compiler will unbox them to primitive types for run-time execution. |
||
< |
<syntaxhighlight lang="scala">1. //Double equal to 1.0 |
||
1.0 //Double, a 64-bit IEEE-754 floating point number (equivalent to Java's double primitive type) |
1.0 //Double, a 64-bit IEEE-754 floating point number (equivalent to Java's double primitive type) |
||
2432311.7567374 //Double |
2432311.7567374 //Double |
||
Line 1,281: | Line 1,281: | ||
Double.PositiveInfinity |
Double.PositiveInfinity |
||
Double.NegativeInfinity |
Double.NegativeInfinity |
||
</syntaxhighlight> |
|||
</lang> |
|||
Values that are outside the bounds of a type will give compiler-time errors when trying to force them to that type. |
Values that are outside the bounds of a type will give compiler-time errors when trying to force them to that type. |
||
=={{header|Scheme}}== |
=={{header|Scheme}}== |
||
< |
<syntaxhighlight lang="scheme"> |
||
.2 ; 0.2 |
.2 ; 0.2 |
||
2. ; 2.0 |
2. ; 2.0 |
||
Line 1,295: | Line 1,295: | ||
; #t |
; #t |
||
(inexact? 2) |
(inexact? 2) |
||
; #f</ |
; #f</syntaxhighlight> |
||
=={{header|Seed7}}== |
=={{header|Seed7}}== |
||
The type [http://seed7.sourceforge.net/libraries/float.htm float] consists of single precision floating point numbers. Float literals are base 10 and contain a decimal point. There must be at least one digit before and after the decimal point. An exponent part, which is introduced with E or e, is optional. The exponent can be signed, but the mantissa is not. A literal does not have a sign, + or - are unary operations. Examples of float literals are: |
The type [http://seed7.sourceforge.net/libraries/float.htm float] consists of single precision floating point numbers. Float literals are base 10 and contain a decimal point. There must be at least one digit before and after the decimal point. An exponent part, which is introduced with E or e, is optional. The exponent can be signed, but the mantissa is not. A literal does not have a sign, + or - are unary operations. Examples of float literals are: |
||
< |
<syntaxhighlight lang="seed7"> |
||
3.14159265358979 |
3.14159265358979 |
||
1.0E-12 |
1.0E-12 |
||
0.1234 |
0.1234 |
||
</syntaxhighlight> |
|||
</lang> |
|||
The functions [http://seed7.sourceforge.net/libraries/float.htm#str%28ref_float%29 str] and the operators [http://seed7.sourceforge.net/libraries/float.htm#%28ref_float%29digits%28ref_integer%29 digits] and [http://seed7.sourceforge.net/libraries/float.htm#%28attr_float%29parse%28in_string%29 parse] create and accept float literals with sign. |
The functions [http://seed7.sourceforge.net/libraries/float.htm#str%28ref_float%29 str] and the operators [http://seed7.sourceforge.net/libraries/float.htm#%28ref_float%29digits%28ref_integer%29 digits] and [http://seed7.sourceforge.net/libraries/float.htm#%28attr_float%29parse%28in_string%29 parse] create and accept float literals with sign. |
||
Line 1,309: | Line 1,309: | ||
=={{header|Sidef}}== |
=={{header|Sidef}}== |
||
< |
<syntaxhighlight lang="ruby">say 1.234; |
||
say .1234; |
say .1234; |
||
say 1234e-5; |
say 1234e-5; |
||
say 12.34e5;</ |
say 12.34e5;</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>1.234 |
<pre>1.234 |
||
Line 1,320: | Line 1,320: | ||
=={{header|Smalltalk}}== |
=={{header|Smalltalk}}== |
||
< |
<syntaxhighlight lang="smalltalk">2.0 |
||
45e6 |
45e6 |
||
45e+6 |
45e+6 |
||
78e-9 |
78e-9 |
||
1.2E34</ |
1.2E34</syntaxhighlight> |
||
base 2 mantissa: |
base 2 mantissa: |
||
< |
<syntaxhighlight lang="smalltalk">2r1010.0 -> 10.0 |
||
2r0.01 -> 0.25 |
2r0.01 -> 0.25 |
||
2r1010e5 -> 320.0. "hint: = 10*(2ˆ5)"</ |
2r1010e5 -> 320.0. "hint: = 10*(2ˆ5)"</syntaxhighlight> |
||
base 2 mantissa and base 2 exponent: |
base 2 mantissa and base 2 exponent: |
||
< |
<syntaxhighlight lang="smalltalk">2r1010e2r0101 -> 320.0 "hint: = 10*(2ˆ5)"</syntaxhighlight> |
||
Complex numbers: |
Complex numbers: |
||
< |
<syntaxhighlight lang="smalltalk">3.1i |
||
2.0+4.5i</ |
2.0+4.5i</syntaxhighlight> |
||
=={{header|Stata}}== |
=={{header|Stata}}== |
||
Line 1,342: | Line 1,342: | ||
Examples: |
Examples: |
||
< |
<syntaxhighlight lang="stata">.3 |
||
1.5 |
1.5 |
||
-1.5e10 |
-1.5e10 |
||
3.15e-100</ |
3.15e-100</syntaxhighlight> |
||
=={{header|Swift}}== |
=={{header|Swift}}== |
||
< |
<syntaxhighlight lang="swift">let double = 1.0 as Double // Double precision |
||
let float = 1.0 as Float // Single precision |
let float = 1.0 as Float // Single precision |
||
let scientific = 1.0E-12 |
let scientific = 1.0E-12 |
||
Line 1,356: | Line 1,356: | ||
let div = 1.1 / 2 // Double |
let div = 1.1 / 2 // Double |
||
let div1 = 1 / 2 // 0</ |
let div1 = 1 / 2 // 0</syntaxhighlight> |
||
=={{header|Tcl}}== |
=={{header|Tcl}}== |
||
Line 1,371: | Line 1,371: | ||
=={{header|Ursa}}== |
=={{header|Ursa}}== |
||
Cygnus/X Ursa (the standard Ursa interpreter) is written in Java and supports Java style floating-point literals. |
Cygnus/X Ursa (the standard Ursa interpreter) is written in Java and supports Java style floating-point literals. |
||
< |
<syntaxhighlight lang="ursa">1. |
||
1.0 |
1.0 |
||
2432311.7567374 |
2432311.7567374 |
||
Line 1,381: | Line 1,381: | ||
758832D |
758832D |
||
728832F |
728832F |
||
1.0F</ |
1.0F</syntaxhighlight> |
||
=={{header|Verbexx}}== |
=={{header|Verbexx}}== |
||
< |
<syntaxhighlight lang="verbexx">// Floating-point Literals: |
||
// |
// |
||
// If present,the exponent must be of the form: |
// If present,the exponent must be of the form: |
||
Line 1,439: | Line 1,439: | ||
// Underscores can also appear in the exponent, after the first digit: |
// Underscores can also appear in the exponent, after the first digit: |
||
@SAY -1_E-0__2_f32 1.e+0___5_5____ -1.0_E123_456_789_987_654_321__fD debug:;</ |
@SAY -1_E-0__2_f32 1.e+0___5_5____ -1.0_E123_456_789_987_654_321__fD debug:;</syntaxhighlight> |
||
=={{header|Vim Script}}== |
=={{header|Vim Script}}== |
||
Line 1,456: | Line 1,456: | ||
{{works with|VBA|6.5}} |
{{works with|VBA|6.5}} |
||
{{works with|VBA|7.1}} |
{{works with|VBA|7.1}} |
||
< |
<syntaxhighlight lang="vb">Sub Main() |
||
Dim d As Double ' 8 Bytes, type specifier = # |
Dim d As Double ' 8 Bytes, type specifier = # |
||
Dim s As Single ' 4 Bytes, type specifier = ! |
Dim s As Single ' 4 Bytes, type specifier = ! |
||
Line 1,477: | Line 1,477: | ||
s = 0! |
s = 0! |
||
s = 2! * 10 ^ 3 |
s = 2! * 10 ^ 3 |
||
End Sub</ |
End Sub</syntaxhighlight> |
||
There is no built-in support for not-a-number, but here's a way to handle that anyway: |
There is no built-in support for not-a-number, but here's a way to handle that anyway: |
||
< |
<syntaxhighlight lang="vb">Option Explicit |
||
Public Declare Function RtlCompareMemory Lib "ntdll.dll" _ |
Public Declare Function RtlCompareMemory Lib "ntdll.dll" _ |
||
(ByRef Source1 As Any, ByRef Source2 As Any, ByVal Length As Long) As Long |
(ByRef Source1 As Any, ByRef Source2 As Any, ByVal Length As Long) As Long |
||
Line 1,501: | Line 1,501: | ||
Debug.Assert IsNAN(d2) |
Debug.Assert IsNAN(d2) |
||
Debug.Print CStr(d2) |
Debug.Print CStr(d2) |
||
End Sub</ |
End Sub</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>-1,#IND</pre> |
<pre>-1,#IND</pre> |
||
Line 1,513: | Line 1,513: | ||
All numbers are instances of the built-in Num class which is always 8 bytes in size. Integers are really just floating point numbers which have no decimal part. |
All numbers are instances of the built-in Num class which is always 8 bytes in size. Integers are really just floating point numbers which have no decimal part. |
||
< |
<syntaxhighlight lang="ecmascript">var f = 123.45 |
||
var g = 0.12345 // .12345 not allowed |
var g = 0.12345 // .12345 not allowed |
||
var h = 1.234e2 |
var h = 1.234e2 |
||
var i = -0.0 |
var i = -0.0 |
||
System.print([f, g, h, i])</ |
System.print([f, g, h, i])</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,525: | Line 1,525: | ||
=={{header|XPL0}}== |
=={{header|XPL0}}== |
||
<syntaxhighlight lang="xpl0">0. |
|||
<lang XPL0>0. |
|||
.1 |
.1 |
||
1e3 |
1e3 |
||
123.456E-300 |
123.456E-300 |
||
-123_456_789e+123</ |
-123_456_789e+123</syntaxhighlight> |
||
=={{header|Z80 Assembly}}== |
=={{header|Z80 Assembly}}== |
||
Line 1,535: | Line 1,535: | ||
You'll have to do it the hard way unfortunately. I used an IEEE-754 floating point calculator to figure this out. |
You'll have to do it the hard way unfortunately. I used an IEEE-754 floating point calculator to figure this out. |
||
The Z80 doesn't natively have any commands for floats, so you'll have to do it yourself. |
The Z80 doesn't natively have any commands for floats, so you'll have to do it yourself. |
||
< |
<syntaxhighlight lang="z80">byte &DB,&0F,&49,&40 ;0x40490FDB or 3.141592654 (single-precision)</syntaxhighlight> |
||
=={{header|zkl}}== |
=={{header|zkl}}== |
||
zkl requires something on both sides of the dot for a thing to be a float |
zkl requires something on both sides of the dot for a thing to be a float |
||
< |
<syntaxhighlight lang="zkl">1.0, 0.1, 3.1415, 1.e-100, 1.2e100, -1e10, -1e+10, 123.456E-300</syntaxhighlight> |
||