Literals/Floating point: Difference between revisions
m
→{{header|Wren}}: Changed to Wren S/H
Puppydrum64 (talk | contribs) |
m (→{{header|Wren}}: Changed to Wren S/H) |
||
(11 intermediate revisions by 9 users not shown) | |||
Line 16:
=={{header|11l}}==
<
2.3
0.3e+34
Line 22:
// single precision (32-bit) floating point literals:
2.3s
0.3e+34s</
=={{header|360 Assembly}}==
[[wp:IBM_hexadecimal_floating_point|IBM hexadecimal floating point]]
<
XDPI DC D'3.141592653589793' long floating-point
Line 40:
* extended floating-point - 128 bits - 16 bytes : 33 decimal digits
* absolute approximate range: 5e-79 to 7e75 </
=={{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.
<
=={{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.
<syntaxhighlight lang="68000devpac">Pi:
DC.L $40490FDB</syntaxhighlight>
=={{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:
<syntaxhighlight lang="ada">
3.141_592_6
1.0E-12
0.13
</syntaxhighlight>
=={{header|Aime}}==
<
5.0
8r # without the "r"(eal) suffix, "8" would be an integer
.125</
=={{header|ALGOL 68}}==
<
# They have the following forms: #
# 1: a digit sequence followed by "." followed by a digit sequence #
Line 85 ⟶ 90:
r := 3.142e-23;
r := 1 234 567 . 9 e - 4;
</syntaxhighlight>
=={{header|ALGOL W}}==
<
real r; long real lr;
% floating point literals have the following forms: %
Line 111 ⟶ 116:
r := 7;
lr := 5.4321L;
end.</
=={{header|Applesoft BASIC}}==
Line 129 ⟶ 134:
=={{header|Arturo}}==
<
print [pi "->" type pi]</
{{out}}
Line 139 ⟶ 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'.
<
2.
.3
Line 145 ⟶ 150:
45e+6
78e-9
1.2E34</
Other implementations of Awk can differ. They might not use floating-point numbers for integers.
Line 151 ⟶ 156:
This Awk program will detect whether each line of input contains a valid integer.
<
print $0 " is a literal number."
next
Line 158 ⟶ 163:
{
print $0 " is not valid."
}</
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 164 ⟶ 169:
=={{header|Axe}}==
Axe does not support floating point literals. However, it does support converting floats to integers and vice versa.
<
float{L₁}→I</
Axe does, however, support fixed-point literals.
<syntaxhighlight lang
There are some mathematical operators in Axe that operate specifically on fixed-point numbers.
=={{header|BBC BASIC}}==
<
REM [-]{digit}[.]{digit}[E[-]{digit}]
Line 185 ⟶ 190:
PRINT 8.9E
PRINT .33E-
PRINT -.</
'''Output:'''
<pre>
Line 212 ⟶ 217:
=={{header|C sharp}}==
Floating point suffixes are not case-sensitive.
<
d = 1d;
d = 1D;
Line 236 ⟶ 241:
m = 12e-12m;
m = 12E-12m;
m = 1_234e-1_2m;</
=={{header|C++}}==
<
int main()
Line 268 ⟶ 273:
std::cout << "\nfloat3: " << float3;
std::cout << "\n";
}</
{{out}}
<pre>
Line 346 ⟶ 351:
=={{header|D}}==
D built-in floating point types include ''float'' (32-bit), ''double'' (64-bit) and ''real'' (machine hardware maximum precision floating point type, 80-bit on x86 machine) and respective complex number types. Here's information for [http://www.d-programming-language.org/lex.html#floatliteral Floating Literals].
=={{header|Delphi}}==
{{works with|Delphi|6.0}}
{{libheader|SysUtils,StdCtrls}}
<syntaxhighlight lang="Delphi">
procedure FloatLiterals(Memo: TMemo);
{Delphi has multiple floating number formats}
var R48: Real48; {48-bit real number}
var SI: Single; {32-bit real number}
var D: Double; {64-bit real number}
var E: Extended; {80-bit real number}
var Cmp: Comp; {}
var Cur: Currency; {Fixed point number for currency}
begin
{Various formats that can be used on input or
as constants assigned to various reals.
Pascal automaically converts integer to
reals as long as the real has enough precision
to hold the value. Consequently, all of the
following constants can be assigned to a real.}
D:=1234;
D:=1.234;
D:=1234E-4;
D:=$7F;
{Reals can also be output in various formats.}
D:=123456789.1234;
Memo.Lines.Add(FloatToStrF(D,ffGeneral,18,4));
Memo.Lines.Add(FloatToStrF(D,ffExponent,18,4));
Memo.Lines.Add(FloatToStrF(D,ffFixed,18,4));
Memo.Lines.Add(FloatToStrF(D,ffNumber,18,4));
Memo.Lines.Add(FloatToStrF(D,ffCurrency,18,4));
Memo.Lines.Add(Format('%10.4f',[D]));
end;
</syntaxhighlight>
{{out}}
<pre>
123456789.123400003
1.23456789123400003E+8
123456789.1234
123,456,789.1234
$123,456,789.1234
123456789.1234
</pre>
=={{header|Dyalect}}==
Line 351 ⟶ 405:
Dyalect built-in types include only one floating point number of type ''Float'' (64-bit). Both regular and scientific notations are supported:
<
var y = 0.174e-17</
EBNF grammar for the floating point number is as follows:
Line 362 ⟶ 416:
| ( "e" | "E") ["+" | "-" ] digit { digit }
).</pre>
=={{header|EasyLang}}==
EasyLang's ability to use hexadecimal literals and floating-point numbers with "E" is undocumented.
<syntaxhighlight lang="easylang">
decimal = 57.1
decimalWithE = 5710E-2
hexadecimal = 0x39.1999999999
print decimal
print decimalWithE
print hexadecimal
</syntaxhighlight>
{{out}}
<pre>
57.10
57.10
57.10
</pre>
=={{header|Eiffel}}==
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:'''<
1.
1.23
Line 372 ⟶ 443:
.5
1.23E4
</syntaxhighlight>
=={{header|Elena}}==
<
r := 23.
r := 1.2e+11r;</
=={{header|Elixir}}==
<
0.123
iex(181)> -123.4
Line 399 ⟶ 470:
iex(187)> 1e4
** (SyntaxError) iex:187: syntax error before: e4</
=={{header|Erlang}}==
Line 405 ⟶ 476:
=={{header|Euphoria}}==
<
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 or Exponential: %g, %g, %g, %g\n",{10,16.123456789,64,123456789.123})
</syntaxhighlight>
{{out}}
<pre>
Line 418 ⟶ 489:
=={{header|Factor}}==
<
+3.14 ! Optional signs
-3.14
Line 444 ⟶ 515:
! normalized hex form ±0x1.MMMMMMMMMMMMMp±EEEE allows any floating-point
! number to be specified precisely according to IEEE 754 representation
+0x1.1234567891234p+0002 ! 4.28444444440952</
=={{header|Fennel}}==
<
3.14159 ;3.14159
Line 459 ⟶ 530:
;;Underscores can optionally be used to split numbers into readable chunks.
123_456.789 ;123456.789
0x1234_5678.9a ;305419896.60156</
=={{header|Forth}}==
Line 510 ⟶ 581:
Some examples, taken from the language documentation follow:
<
Dim a As Double = 123.456
Line 523 ⟶ 594:
Dim j As Single = -123.456e-7f
Dim k As Double = 0#
Dim l As Double = 3.141592653589e3#</
=={{header|FutureBasic}}==
FB can express floating point literals in several ways.
<syntaxhighlight lang="futurebasic">
local fn DoIt
print "Single:"
single s = 1.0 : print s
s = 123.456 : print s
s = -123.0 : print s
s = 43.1e+5 : print s
s = 43.1E5 : print s
s = 3.1 : print s
s = -123.456e-2 : print s
s = 3.141592653589e3 : print s
print
print "Double"
double d = 1.0 : print d
d = 123.456 : print d
d = -123.0 : print d
d = 43.1e+13 : print d
d = 43.1E13 : print d
d = 3.1 : print d
d = -123.456e-7 : print d
d = 3.141592653589e3 : print d
print
print "Float:"
float f = 1.0 : print f
f = 123.456 : print f
f = -123.0 : print f
f = 43.1e+5 : print f
f = 43.1E5 : print f
f = 3.1 : print f
f = -123.456e-2 : print f
f = 3.141592653589e3 : print f
print
print "CFNumberRef:"
CFNumberRef c = @1.0 : print c
c = @123.456 : print c
c = @-123.0 : print c
c = @43.1e+13 : print c
c = @743.1E13 : print c
c = @3.1 : print c
c = @-123.456e-7 : print c
c = @3.141592653589e37 : print c
end fn
fn DoIt
HandleEvents
</syntaxhighlight>
{{output}}
<pre>
Single:
1
123.456
-123
4310000
4310000
3.1
-1.23456
3141.593
Double
1
123.456
-123
431000000000000
431000000000000
3.1
-1.23456e-05
3141.592653589
Float:
1
123.456
-123
4310000
4310000
3.1
-1.23456
3141.593
CFNumberRef:
1
123.456
-123
431000000000000
7431000000000000
3.1
-1.23456e-05
3.141592653589e+37
</pre>
=={{header|GAP}}==
<
22.03e4
4.54e-5</
=={{header|gecho}}==
<
0.0
-1
Line 538 ⟶ 704:
-1.4324
3 4 /
</syntaxhighlight>
=={{header|Go}}==
Line 551 ⟶ 717:
=={{header|Groovy}}==
Solution:
<
println 1.00d // double (IEEE-64)
println 1.00 // BigDecimal (scaled BigInteger)
Line 561 ⟶ 727:
assert 1.00 instanceof BigDecimal
assert 1.00g instanceof BigDecimal
assert 1.00e0 instanceof BigDecimal</
{{out}}
Line 573 ⟶ 739:
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>
Output:
Line 583 ⟶ 749:
The program below shows a full range of valid real literals.
<
every write( ![ 1., .1, 0.1, 2e10, 2E10, 3e-1, .4e2, 1.41e2, 8.e+3, 3.141e43 ])
end</
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 599 ⟶ 765:
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):
<
whitespace ::= whitespacecharacter | whitespacecharacter whitespace
whitespacecharacter ::= ' ' | TAB
Line 621 ⟶ 787:
signed-digits ::= digits | '_' digits
digits ::= digit | digit digits
digit ::= '0'|'1'|'2'|'3'|'4'|'5'|'6'|'7'|'8'|'9'</
e indicates exponential or scientific notation (number on left multiplied by 10 raised to power indicated by number on right)
Line 635 ⟶ 801:
Floating point examples:
<
0 1 _2 3.4 30000 292.227 163.794
16bcafe.babe _16b_cafe.babe _10b11
51966.7 46818.7 _9</
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}}==
<
1.0 //double
2432311.7567374 //double
Line 655 ⟶ 821:
1.0F //float
1 / 2. //double
1 / 2 //int equal to 0</
Values that are outside the bounds of a type will give compiler errors when trying to force them to that type.
=={{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:
<
1.2 => 1.2
1e10 => 10000000000
Line 666 ⟶ 832:
1e1234 => 1.7976931348623157e+308
.1 => 0.1
.1e1 => 1</
=={{header|Julia}}==
{{works with|Julia|0.6}}
<
.1
1.
Line 677 ⟶ 843:
1e+10
1e-10
0x01p-1 # hex float</
=={{header|Kotlin}}==
There are two floating point types: Double (64 bits) and Float (32 bits). The default floating point type is Double.
Double literals must end with a decimal point with at least one digit after it, and/or a scientific notation suffix made with <code>e</code> (or <code>E</code>) followed by an integer literal.
A Float literal is made by appending <code>f</code> (or <code>F</code>) to a Double or Int literal (see [[Literals/Integer#Kotlin|integer literals]]).
<syntaxhighlight lang="kotlin">
val d = 1.0 // Double
val d2 = 1.234e-10 // Double
val f = 728832f // Float
val f2 = 7.28832e5F // Float
</syntaxhighlight>
=={{header|Lasso}}==
<syntaxhighlight lang="lasso">0.0
0.1
-0.1
1.2e3
1.3e+3
1.2e-3</
=={{header|Lingo}}==
<
-- 0.2300
Line 716 ⟶ 890:
-- casting string to float
put float("0.23")
-- 0.23000000</
=={{header|Lua}}==
<
314.159E-2</
=={{header|M2000 Interpreter}}==
We can use Decimal using @ and Currency using # (no exponent part, both types)
<syntaxhighlight lang="m2000 interpreter">
Def ExpType$(x)=Type$(x)
Print ExpType$(-12)="Double", -12
Line 735 ⟶ 909:
Print ExpType$(12.e-5~)="Single", 12.e-5~
Print ExpType$(.1~)="Single", .1~
</syntaxhighlight>
=={{header|Maple}}==
Maple distinguishes "software floats" (of arbitrary precision) and "hardware floats" (of machine precision). To get the latter, use the "HFloat" constructor.
<syntaxhighlight lang="maple">
> 123.456; # decimal notation
123.456
Line 788 ⟶ 962:
> Float(undefined); # "NaN", not-a-number
Float(undefined)
</syntaxhighlight>
Whether a given float is a software or hardware float can be determined by using "type".
<syntaxhighlight lang="maple">
> type( 2.3, 'hfloat' );
false
Line 796 ⟶ 970:
> type( HFloat( 2.3 ), 'hfloat' );
true
</syntaxhighlight>
(There is also a type "sfloat" for software floats, and the type "float", which covers both.)
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<
{6.7^-4,6.7^6,6.7^8}
{0.00049625,90458.4,4.06068*10^6}
Line 814 ⟶ 988:
In accounting form, negative numbers are given in parentheses, and scientific notation is never used.
AccountingForm[{5.6,-6.7,10.^7}]
{5.6,(6.7),10000000.}</
=={{header|Maxima}}==
<
arbitrary length "big floats" */
Line 836 ⟶ 1,010:
bfloat(%pi);
3.141592653589793238462643383279502884197b0</
=={{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.
<
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."
<
lwc1 $f0,0($t0) ;load pi into $f0
Line 851 ⟶ 1,025:
pi:
.word 0x40490FDB ;IEEE-754 representation of 3.1415927</
=={{header|Nemerle}}==
Line 894 ⟶ 1,068:
it's built in ''Rexx'' object and any other Java object that supports floating point numbers.
<
options replace format comments java crossref symbols nobinary
Line 942 ⟶ 1,116:
method normalize(fv) private constant
return fv + 0
</syntaxhighlight>
'''Output:'''
<pre>
Line 974 ⟶ 1,148:
=={{header|Nim}}==
<
x = 2.3
x = 2.0
Line 986 ⟶ 1,160:
var y = 2'f32 # Automatically a float32
var z = 2'f64 # Automatically a float64
</syntaxhighlight>
=={{header|Objeck}}==
<
3 + .14159
3.14159
314.159E-2
</syntaxhighlight>
=={{header|OCaml}}==
Line 1,003 ⟶ 1,177:
Here are some examples:
<
1.0
1. (* it is not possible to write only "1" because OCaml is strongly typed,
and this would be interpreted as an integer *)
1e-10
3.14159_26535_89793</
=={{header|Oforth}}==
Line 1,014 ⟶ 1,188:
A literal floating point number is written with a . and with or without an exponential notation :
<syntaxhighlight lang="oforth">3.14
1.0e-12
0.13
1000.0
.22</
=={{header|PARI/GP}}==
Line 1,054 ⟶ 1,228:
=={{header|Perl}}==
<
.5;
0.5;
Line 1,061 ⟶ 1,235:
# The numbers can be grouped:
100_000_000; # equals to 100000000
</syntaxhighlight>
=={{header|Phix}}==
Line 1,075 ⟶ 1,249:
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
<!--<
<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>
Line 1,083 ⟶ 1,257:
<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>
<!--</
{{out}}
<pre>
Line 1,096 ⟶ 1,270:
=={{header|PHP}}==
More [http://php.net/manual/en/language.types.float.php information] about floating point numbers in PHP.
<syntaxhighlight lang="php">.12
0.1234
1.2e3
7E-10
</syntaxhighlight>
Formal representation:
<pre>
Line 1,128 ⟶ 1,302:
=={{header|PL/I}}==
<syntaxhighlight lang="pl/i">
1.2345e-4 decimal floating-point
7e5 decimal floating-point
Line 1,139 ⟶ 1,313:
or 7.3125 * 2**7
1e5b binary floating-point equals 1 * 2**5
</syntaxhighlight>
=={{header|PureBasic}}==
Line 1,150 ⟶ 1,324:
This is an excerpt of an ANTLR grammar for python obtained from [http://www.antlr.org/grammar/1200715779785/Python.g here].
<
: '.' DIGITS (Exponent)?
| DIGITS '.' Exponent
Line 1,160 ⟶ 1,334:
Exponent
: ('e' | 'E') ( '+' | '-' )? DIGITS
;</
Examples
<
2.3 # 2.2999999999999998
.3 # 0.29999999999999999
Line 1,170 ⟶ 1,344:
.3e-34 # 2.9999999999999999e-35
2.e34 # 1.9999999999999999e+34
</syntaxhighlight>
=={{header|Quackery}}==
Quackery does not support floating point, but it runs on top of Python, which does. So we can reach down into Python and pass floating point numbers back and forth. Here is a cheap but effective way of doing so. We will represent floating point numbers in Quackery as strings. The task requirements are fulfilled by [[Literals/Floating point#Python|the Python entry]].
<code>isfloat</code> conforms that a string is a float by asking Python to validate it.
<code>f</code> adds a sprinkle of syntactic sugar to the Quackery compiler so we can say <code>f 0.5</code> rather that <code>$ "0.5"</code>. (Builders – words defined with <code>builds</code> rather than <code>is</code> – are extensions to the Quackery compiler.)
<code>sin</code>returns the sine of an angle expressed in radians, so that we can demonstrate usage of <code>f</code> here.
<syntaxhighlight lang="Quackery"> [ $ \
try:
float(string_from_stack())
except:
to_stack(False)
else:
to_stack(True)
\ python ] is isfloat ( $ --> b )
[ nextword
dup isfloat not if
[ $ '"f" needs to be followed by a number.'
message put bail ]
' [ ' ] swap nested join
nested swap dip join ] builds f ( [ $ --> [ $ )
[ $ \
import math
a = string_from_stack()
a = str(math.sin(float(a)))
string_to_stack(a) \ python ] is sin ( $ --> $ )
</syntaxhighlight>
{{out}}
Demonstrating usage as a dialogue in the Quackery shell (REPL).
<pre>/O> f 0.5
... dup echo$ cr
... sin echo$ cr
...
0.5
0.479425538604203
</pre>
=={{header|Racket}}==
<
#lang racket
.2
Line 1,184 ⟶ 1,403:
2.0f0 ; single float
1.0t0 ; extended 80-bit float (when available on platform)
</syntaxhighlight>
Output:
Line 1,201 ⟶ 1,420:
(formerly Perl 6)
Floating point numbers (the Num type) are written in the standard 'e' scientific notation:
<syntaxhighlight lang="raku"
6.02e23
-2e48
1e-9
1e0</
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,211 ⟶ 1,430:
=={{header|REXX}}==
All values in REXX are character strings, so a value could hold such things as these (decimal) numbers:
<
something = '127' /*exactly the same as the above. */
something = 1.27e2
something = 1.27E2
something = 1.27E+2
something = ' + 0001.27e+00000000000000002 '</
To forcibly express a value in exponential notation, REXX has a built-in function '''format''' that can be used.
Line 1,224 ⟶ 1,443:
</pre>
by the '''format''' BIF.
<
say something
say format(something,,,,0)</
'''output'''
<pre>
Line 1,235 ⟶ 1,454:
There are other options for the '''format''' BIF to force any number of digits before and/or after the decimal point, and/or specifying the number of digits in the exponent. <br><br>
=={{header|RPL}}==
Floating point numbers exist only in decimal format. They can be entered using the scientific format: <code>3.1416E2</code> is equivalent to <code>314.16</code>.
Display can be forced to <code>SCI</code>entific or "<code>ENG</code>ineering" format (the exponent being a multiple of 3), with a defined number of digits after the decimal point of the mantissa:
1: { 123.45 0.012345 }
3 SCI
1: { 1.235E+02 1.245E-02 }
3 ENG
1: { 123.5E0 12.45E-3 }
=={{header|Ruby}}==
Line 1,244 ⟶ 1,472:
=={{header|Rust}}==
The fractional part may be elided (so 1. is valid) but the integer part may not (so .0 is not valid).
<
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
1_000.2_f32 // Underscores may appear anywhere in the number for clarity.</
=={{header|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.
<
1.0 //Double, a 64-bit IEEE-754 floating point number (equivalent to Java's double primitive type)
2432311.7567374 //Double
Line 1,276 ⟶ 1,504:
Double.PositiveInfinity
Double.NegativeInfinity
</syntaxhighlight>
Values that are outside the bounds of a type will give compiler-time errors when trying to force them to that type.
=={{header|Scheme}}==
<
.2 ; 0.2
2. ; 2.0
Line 1,290 ⟶ 1,518:
; #t
(inexact? 2)
; #f</
=={{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:
<
3.14159265358979
1.0E-12
0.1234
</syntaxhighlight>
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,304 ⟶ 1,532:
=={{header|Sidef}}==
<
say .1234;
say 1234e-5;
say 12.34e5;</
{{out}}
<pre>1.234
Line 1,315 ⟶ 1,543:
=={{header|Smalltalk}}==
<
45e6
45e+6
78e-9
1.2E34</
base 2 mantissa:
<
2r0.01 -> 0.25
2r1010e5 -> 320.0. "hint: = 10*(2ˆ5)"</
base 2 mantissa and base 2 exponent:
<
Complex numbers:
<
2.0+4.5i</
=={{header|Stata}}==
Line 1,337 ⟶ 1,565:
Examples:
<
1.5
-1.5e10
3.15e-100</
=={{header|Swift}}==
<
let float = 1.0 as Float // Single precision
let scientific = 1.0E-12
Line 1,351 ⟶ 1,579:
let div = 1.1 / 2 // Double
let div1 = 1 / 2 // 0</
=={{header|Tcl}}==
Line 1,366 ⟶ 1,594:
=={{header|Ursa}}==
Cygnus/X Ursa (the standard Ursa interpreter) is written in Java and supports Java style floating-point literals.
<
1.0
2432311.7567374
Line 1,376 ⟶ 1,604:
758832D
728832F
1.0F</
=={{header|Verbexx}}==
<
//
// If present,the exponent must be of the form:
Line 1,434 ⟶ 1,662:
// 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:;</
=={{header|Vim Script}}==
Line 1,451 ⟶ 1,679:
{{works with|VBA|6.5}}
{{works with|VBA|7.1}}
<
Dim d As Double ' 8 Bytes, type specifier = #
Dim s As Single ' 4 Bytes, type specifier = !
Line 1,472 ⟶ 1,700:
s = 0!
s = 2! * 10 ^ 3
End Sub</
There is no built-in support for not-a-number, but here's a way to handle that anyway:
<
Public Declare Function RtlCompareMemory Lib "ntdll.dll" _
(ByRef Source1 As Any, ByRef Source2 As Any, ByVal Length As Long) As Long
Line 1,496 ⟶ 1,724:
Debug.Assert IsNAN(d2)
Debug.Print CStr(d2)
End Sub</
{{out}}
<pre>-1,#IND</pre>
Line 1,508 ⟶ 1,736:
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.
<
var g = 0.12345 // .12345 not allowed
var h = 1.234e2
var i = -0.0
System.print([f, g, h, i])</
{{out}}
Line 1,520 ⟶ 1,748:
=={{header|XPL0}}==
<syntaxhighlight lang="xpl0">0.
.1
1e3
123.456E-300
-123_456_789e+123</
=={{header|Z80 Assembly}}==
{{trans|6502 Assembly}}
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.
<syntaxhighlight lang="z80">byte &DB,&0F,&49,&40 ;0x40490FDB or 3.141592654 (single-precision)</syntaxhighlight>
=={{header|zkl}}==
zkl requires something on both sides of the dot for a thing to be a float
<
|