Literals/Floating point: Difference between revisions

Content deleted Content added
Drkameleon (talk | contribs)
Thundergnat (talk | contribs)
Rename Perl 6 -> Raku, alphabetize, minor clean-up
Line 313: Line 313:
1.23E4
1.23E4
</lang>
</lang>

=={{header|Elena}}==
=={{header|Elena}}==
<lang elena>real r := 1;
<lang elena>real r := 1;
Line 513: Line 514:
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.
{{libheader|Icon Programming Library}}
{{libheader|Icon Programming Library}}
[http://www.cs.arizona.edu/icon/library/src/procs/printf The IPL library routine printf provides a broader range of formatting choices.]
[http://www.cs.arizona.edu/icon/library/src/procs/printf The IPL library routine printf provides a broader range of formatting choices.]


=={{header|J}}==
=={{header|J}}==
Line 565: Line 566:


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|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:
<lang sh>1.0 => 1
1.2 => 1.2
1e10 => 10000000000
1e100 => 1e+100
1e1234 => 1.7976931348623157e+308
.1 => 0.1
.1e1 => 1</lang>


=={{header|Java}}==
=={{header|Java}}==
Line 591: Line 582:
1 / 2 //int equal to 0</lang>
1 / 2 //int equal to 0</lang>
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}}==
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:
<lang sh>1.0 => 1
1.2 => 1.2
1e10 => 10000000000
1e100 => 1e+100
1e1234 => 1.7976931348623157e+308
.1 => 0.1
.1e1 => 1</lang>


=={{header|Julia}}==
=={{header|Julia}}==
Line 971: Line 972:
100_000_000; # equals to 100000000
100_000_000; # equals to 100000000
</lang>
</lang>

=={{header|Perl 6}}==
Floating point numbers (the Num type) are written in the standard 'e' scientific notation:
<lang perl6>2e2 # same as 200e0, 2e2, 200.0e0 and 2.0e2
6.02e23
-2e48
1e-9
1e0</lang>

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.


=={{header|Phix}}==
=={{header|Phix}}==
Line 1,100: Line 1,091:
1.0t0
1.0t0
</pre>
</pre>

=={{header|Raku}}==
(formerly Perl 6)
Floating point numbers (the Num type) are written in the standard 'e' scientific notation:
<lang perl6>2e2 # same as 200e0, 2e2, 200.0e0 and 2.0e2
6.02e23
-2e48
1e-9
1e0</lang>

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.


=={{header|REXX}}==
=={{header|REXX}}==
Line 1,220: Line 1,222:
base 2 mantissa and base 2 exponent:
base 2 mantissa and base 2 exponent:
<lang smalltalk>2r1010e2r0101 -> 320.0</lang>
<lang smalltalk>2r1010e2r0101 -> 320.0</lang>

=={{header|Stata}}==
=={{header|Stata}}==
Only decimal floating-point are supported, computations are done in double precision (but storage can be made in integer or single floating-point as well).
Only decimal floating-point are supported, computations are done in double precision (but storage can be made in integer or single floating-point as well).