Literals/Floating point
You are encouraged to solve this task according to the task description, using any language you may know.
Programming languages have different ways of expressing floatingpoint literals.
 Task
Show how floatingpoint literals can be expressed in your language: decimal or other bases, exponential notation, and any other special features.
You may want to include a regular expression or BNF/ABNF/EBNF defining allowable formats for your language.
 Related tasks
Contents
 1 Ada
 2 Aime
 3 ALGOL 68
 4 ALGOL W
 5 Applesoft BASIC
 6 AWK
 7 Axe
 8 BBC BASIC
 9 bc
 10 C
 11 C#
 12 Clojure
 13 Common Lisp
 14 D
 15 Eiffel
 16 Elixir
 17 Erlang
 18 Euphoria
 19 Forth
 20 Fortran
 21 FreeBASIC
 22 GAP
 23 gecho
 24 Go
 25 Groovy
 26 Haskell
 27 Icon and Unicon
 28 J
 29 jq
 30 Java
 31 Kotlin
 32 Lasso
 33 Lingo
 34 Lua
 35 Maple
 36 Mathematica
 37 Maxima
 38 Nemerle
 39 NetRexx
 40 Nim
 41 Objeck
 42 OCaml
 43 Oforth
 44 PARI/GP
 45 Pascal
 46 Perl
 47 Perl 6
 48 Phix
 49 PHP
 50 PicoLisp
 51 PL/I
 52 PureBasic
 53 Python
 54 Racket
 55 REXX
 56 Ruby
 57 Rust
 58 Scheme
 59 Seed7
 60 Sidef
 61 Smalltalk
 62 Swift
 63 Tcl
 64 Ursa
 65 Vim Script
 66 XPL0
 67 zkl
Ada[edit]
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:
3.141_592_6
1.0E12
0.13
Aime[edit]
3.14
5.0
8r # without the "r"(eal) suffix, "8" would be an integer
.125
ALGOL 68[edit]
# floating point literals are called REAL denotations in Algol 68 #
# They have the following forms: #
# 1: a digit sequence followed by "." followed by a digit sequence #
# 2: a "." followed by a digit sequence #
# 3: forms 1 or 2 followed by "e" followed by an optional sign #
# followed by a digit sequence #
# 4: a digit sequence follows by "e" followed by an optional sign #
# followed by a digit sequence #
# #
# The "e" indicates the following optionallysigned digit sequence is #
# the exponent of the literal. #
# If the implementation allows, a "times ten to the power symbol" #
# can be used to replace "e"  e.g. a subscript "10" character #
# #
# spaces can appear anywhere in the denotation #
# Examples: #
REAL r;
r := 1.234;
r := .987;
r := 4.2e9;
r := .4e+23;
r := 1e10;
r := 3.142e23;
r := 1 234 567 . 9 e  4;
ALGOL W[edit]
begin
real r; long real lr;
% floating point literals have the following forms: %
% 1  a digit sequence followed by "." followed by a digit sequence %
% 2  a digit sequence followed by "." %
% 3  "." followed by a digit sequence %
% 4  one of the above, followed by "'" followed by an optional sign %
% folloed by a digit sequence %
% the literal can be followed by "L", indicating it is long real %
% the literal can be followed by "I", indicating it is imaginary %
% the literal can be followed by "LI" or "IL" indicating it is a long %
% imaginary number %
% an integer literal ( digit sequence ) can also be used where a %
% floating point literal is required %
% nonimaginary examples: %
r := 1.23;
r := 1.;
r := .9;
r := 1.23'5;
r := 1.'+4;
r := .9'12;
r := 7;
lr := 5.4321L;
end.
Applesoft BASIC[edit]
All numeric literals are treated as floating point. (In the Apple II world, Applesoft was sometimes called "floatingpoint BASIC" to contrast it with Integer BASIC.)
0 19 3 29.59 239.4 1E10 1.9E+09 6.66E32
AWK[edit]
With the One True Awk (nawk), all numbers are floatingpoint. A numeric literal consists of one or more digits '09', 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 '09'.
2
2.
.3
45e6
45e+6
78e9
1.2E34
Other implementations of Awk can differ. They might not use floatingpoint numbers for integers.
This Awk program will detect whether each line of input contains a valid integer.
/^([09]+(\.[09]*)?\.[09]+)([Ee][+]?[09]+)?$/ {
print $0 " is a literal number."
next
}
{
print $0 " is not valid."
}
A leading plus or minus sign (as in +23 or 14) 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; 14 ** 2 acts like (14 ** 2), not like (14) ** 2.
Axe[edit]
Axe does not support floating point literals. However, it does support converting floats to integers and vice versa.
123→float{L₁}
float{L₁}→I
Axe does, however, support fixedpoint literals.
12.25→A
There are some mathematical operators in Axe that operate specifically on fixedpoint numbers.
BBC BASIC[edit]
REM Floatingpoint literal syntax:
REM []{digit}[.]{digit}[E[]{digit}]
REM Examples:
PRINT 123.456E1
PRINT 1000.0
PRINT 1E5
REM Valid but nonstandard examples:
PRINT 67.
PRINT 8.9E
PRINT .33E
PRINT .
Output:
12.3456 1000 1E5 67 8.9 0.33 0
bc[edit]
A literal floating point number can be written as .NUMBER
, NUMBER.
or NUMBER.NUMBER
where NUMBER
consists of the hexadecimal digits 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F
. If digits in the number are greater than or equal to the current value of ibase
(i.e. the input number radix) the behaviour is undefined.
12.34 .34 99. ABC.DEF
C[edit]
Floatingpoint numbers can be given in decimal or hexadecimal. Decimal floatingpoint numbers must have at least one of a decimal point and an exponent part, which is marked by an E:
((\d*\.\d+\d+\.)([eE][+]?[09]+)?[flFL]?)([09]+[eE][+]?[09]+[flFL]?)
Hexadecimal is similar, but allowing AF as well as 09. They have a binary exponent part marked with a P instead of a decimal exponent:
(0[xX]([09afAF]*\.[09afAF]+[09afAF]+\.)([pP][+]?\d+[flFL]?)(0[xX][09afAF]+[pP][+]?\d+[flFL]?)
C#[edit]
Floating point suffixes are not casesensitive.
double d = 1;
d = 1d;
d = 1D;
d = 1.2; //double is the default if there's no suffix
d = 1.2d; //The suffix is redundant here
d = .2;
d = 12e12;
d = 12E12;
d = 1_234e1_2; //digit separators are allowed since C# 7
float f = 1;
f = 1f;
f = 1F;
f = 1.2f;
f = .2f;
f = 12e12f;
f = 12E12f;
f = 1_234e1_2f;
decimal m = 1;
m = 1m;
m = 1m;
m = 1.2m;
m = .2m;
m = 12e12m;
m = 12E12m;
m = 1_234e1_2m;
Clojure[edit]
Clojure supports both standard and scientific notation.
user=> 1. 1.0 user=> 1.0 1.0 user=> 3.1415 3.1415 user=> 1.234E10 1.234E10 user=> 1e100 1.0E100 user=> (Float/valueOf "1.0f") 1.0
Clojure also supports returning ratios (fractions) if you divide integers. These are not subject to roundoff error. If you do specify a floating point in the division, it will return a floating point value.
user=> (/ 1 3) 1/3 user=> (/ 1.0 3) 0.3333333333333333
Common Lisp[edit]
The grammar for floating point literals in EBNF (ISO/IEC 14977):
float = [ sign ], { decimaldigit }, decimalpoint, decimaldigit, { decimaldigit }, [exponent]  [ sign ], decimaldigit, { decimaldigit }, [ decimalpoint, { decimaldigit } ], exponent ; exponent = exponentmarker, [ sign ], decimaldigit, { decimaldigit } ; sign = "+"  "" ; decimalpoint = "." ; decimaldigit = "0"  "1"  "2"  "3"  "4"  "5"  "6"  "7"  "8"  "9" ; exponentmarker = "e"  "E"  "s"  "S"  "d"  "D"  "f"  "F"  "l"  "L" ;
Common Lisp implementations can provide up to 4 different float subtypes: shortfloat, singlefloat, doublefloat and longfloat. The exponent marker specifies the type of the literal. "e"/"E" denotes the default floating point subtype (it is initially singlefloat but you can set it with the global variable *READDEFAULTFLOATFORMAT*
to any of the other subtypes).
The standard only recommends a minimum precision and exponent size for each subtype and an implementation doesn't have to provide all of them:
Format  Minimum Precision  Minimum Exponent Size  Short (s/S)  13 bits  5 bits Single (f/F)  24 bits  8 bits Double (d/D)  50 bits  8 bits Long (l/L)  50 bits  8 bits
Some examples:
> 1.0 1.0 > .1 0.1 > 1e4 1.0E4 > 1d2 100.0d0 > .1f3 100.0 > .001l300 1.0L303
Note that 123.
is not a floating point number but an integer:
> (floatp 123.) NIL > (integerp 123.) T
D[edit]
D builtin floating point types include float (32bit), double (64bit) and real (machine hardware maximum precision floating point type, 80bit on x86 machine) and respective complex number types. Here's information for Floating Literals.
Eiffel[edit]
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
1e5
.5
1.23E4
Elixir[edit]
iex(180)> 0.123
0.123
iex(181)> 123.4
123.4
iex(182)> 1.23e4
1.23e4
iex(183)> 1.2e3
0.0012
iex(184)> 1.23E4
1.23e4
iex(185)> 10_000.0
1.0e4
iex(186)> .5
** (SyntaxError) iex:186: syntax error before: '.'
iex(186)> 2. + 3
** (CompileError) iex:186: invalid call 2.+(3)
iex(187)> 1e4
** (SyntaxError) iex:187: syntax error before: e4
Erlang[edit]
Floating point literal examples: 1.0 , 1.0 , 1.2e3 , 1.2e3 and 1.2E3 , 1.2E3 .
Euphoria[edit]
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})
 Output:
Exponential: 1.012460e+001, 1.023560e+001, 1.612346e+001, 6.412000e+001 Floating Point 10.125, 10.236, +16.123, 64.120 Floating Point or Exponential: 10, 16.1235, 64, 1.23457e+008
Forth[edit]
Unlike most other languages, floating point literals in Forth are distinguished by their exponent ('E' or 'e') rather than their decimal point ('.' or ','). Numeric literals with just a decimal point are regarded as twocell double precision integers. From the ANS Forth standards document:
Convertible string := <significand><exponent> <significand> := [<sign>]<digits>[.<digits0>] <exponent> := E[<sign>]<digits0> <sign> := { +   } <digits> := <digit><digits0> <digits0> := <digit>* <digit> := { 0  1  2  3  4  5  6  7  8  9 }
These are examples of valid representations of floatingpoint numbers in program source:
1E 1.E 1.E0 +1.23E1 1.23E+1
Fortran[edit]
Floatingpoint literals involve a decimal point, otherwise they're integers. The rule is <sign><digits><.><digits><exponent> with each optional  except that there must be some digits! Spaces are irrelevant in source files, so 3 .141 159 would be acceptable, however when data are read, internal spaces are not allowed so " 3.14" would be rejected  at least for freeformat (or "list") style input. With formatted input, spaces are considered to be zeroes and a data field lacking a decimal point can have one assumed so that " 31" read by F4.1 would yield 3.1. There is no requirement that there be digits before the decimal point, nor digits after the decimal point (if there are digits before), so .5 and 5. are both acceptable.
The status of the sign is delicate, being a matter of context. In a DATA statement or in an assignment such as x = 5.5, the sign is a part of the number, but not in an arithmetic expression such as y = x*5.5 which has two operators in a row and is rejected. x*(5.5) is accepted and the sign is a part of the number.
The exponent part signifies a power of ten and if present, has the form <E or D><sign><integer>, the sign optional, where E signifies a singleprecision number and D a doubleprecision number, irrespective of the number of digits offered in the number. Thus, a constant 3.14159265 will be doubleprecision only if there follows a D, presumably with a zero exponent. As a result, 1.0D0 is not the same as 1.0E0, even though they are equal, and a calculation such as 4*atan(1.0) will be in single precision unless it is 4*atan(1.0D0) or similar. Some compilers offer an option to regard all constants as being in double precision irrespective of E or D, but in the absence of that, 1.15 or 1.15E0 will not equal 1.15D0 because most decimal fractions are recurring sequences in binary, and if such constants were assigned to suitable variables and printed with one decimal digit, then on common computers, the doubleprecision value will come out as 10.2 because with 53bit precision its value is (exactly) 10·1500000000000003552713678800500929355621337890625, which rounds up, while in single precision it is (exactly) 10·1499996185302734375, which rounds down.
There are also options for specifying constants as hexadecimal sequences, and if assigned to a floatingpoint variable, then Z"FFFFFFFFFFFFFFFF" will generate a (double precision) NaN value while Z"FFF0000000000000" will generate negative infinity, on cpus supporting such features. Similarly with octal and binary sequences. In these cases, the bit patterns are as they will be in the floatingpoint format, not as a number expressed in hexadecimal, etc. Thus, pi = Z"40490FDB" or 1000000010010010000111111011011, which is not 11.00100100001111110... at all.
Complex number constants are typically specified as (x,y) where x and y are floatingpoint literals; there is no provision for complex integers.
FreeBASIC[edit]
FreeBASIC has two floating point types : Single (4 bytes) and Double (8 bytes)
Numeric literals of these types can be specified by using the following suffixes:
Single !, f or F : Double #
However, this is not usually necessary as the compiler will automatically infer the type from the context and the two types are implicitly convertible to each other or explicitly convertible using the CSng or CDbl functions. However, conversions from Double to Single may lose precision.
All numeric literals which include a decimal point or exponent (i.e. scientific notation) are considered to be of floating point rather than integral type and are generally of the form:
number[.[fraction]][((DE) [+] exponent)(DE)][suffix]
or
.fraction[((DE) [+] exponent)(DE)][suffix]
Where scientific notation is used, D denotes Double precision and E denotes default precision , though these can be overridden by the suffix, if there is one. They can also be used on their own, without a following exponent.
The default precision is Double unless the 'QB' dialect of the language is used (for compatibility with QuickBasic code) where numbers of no more than 7 digits are considered to be Single precision.
Some examples, taken from the language documentation follow:
' FB 1.05.0 Win64 (default dialect)
Dim a As Double = 123.456
Dim b As Double = 123.0
Dim c As Double = 123.0d
Dim d As Double = 123e
Dim e As Double = 743.1e+13
Dim f As Double = 743.1D13
Dim g As Double = 743.1E13
Dim h As Single = 743D! Rem ! overrides D
Dim i As Single = 3.1!
Dim j As Single = 123.456e7f
Dim k As Double = 0#
Dim l As Double = 3.141592653589e3#
GAP[edit]
3.14
22.03e4
4.54e5
gecho[edit]
0.0
1
1.2
1.4324
3 4 /
Go[edit]
See relevant section of language reference. Basically they are base 10, need either a decimal point or an exponent, and specify no precision or representation. The exponent can be signed, but the mantissa is not. A leading minus sign would be an operator and not part of the floating point literal. Examples,
0. 1e3 1e300 6.02E+23
Groovy[edit]
Solution:
println 1.00f // float (IEEE32)
println 1.00d // double (IEEE64)
println 1.00 // BigDecimal (scaled BigInteger)
println 1.00g // BigDecimal
println 1.00e0 // BigDecimal
assert 1.00f instanceof Float
assert 1.00d instanceof Double
assert 1.00 instanceof BigDecimal
assert 1.00g instanceof BigDecimal
assert 1.00e0 instanceof BigDecimal
 Output:
1.0 1.0 1.00 1.00 1.00
Haskell[edit]
Haskell supports decimal representation of float literals, with or without an exponent. For more information, see the relevant portion of the Haskell 98 Report.
main = print [0.1,23.3,35e1,56E+2,14.67e1]
Output:
[0.1,23.3,3.5,5600.0,146.7]
Icon and Unicon[edit]
Real literals can be represented in two forms by (a) decimal literals, or (b) exponent literals. There is no sign as + and  are unary operators.
The program below shows a full range of valid real literals.
procedure main()
every write( ![ 1., .1, 0.1, 2e10, 2E10, 3e1, .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.
The IPL library routine printf provides a broader range of formatting choices.
J[edit]
This paragraph highlights current implementation specific details of internal types: J has a syntax for specifying numbers, but numeric constants are stored in their most compact implementation; for example, 2.1
is a floating point number, while 2.0
is an integer and 1.0
is a boolean. If the exact type of a value is important, an expression may be used; for example, 1.10.1
produces a floating point result.
J's numeric constant minilanguage allows the specification of numbers which are not floating point, but as indicated above, numeric type in J is a semantic triviality and not a syntactic feature. (And this pervades the language. For example, 1+1 is 2, despite the result having a different type from both of the arguments. Or, for example, if maxint is the largest value represented using an integer type, maxint+1 will produce a floating point result instead of an error or a wraparound.)
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 language specification allows 1.2e3.4 but the current implementation does not support fractional powers of 10 in numeric constants):
numericconstant ::= numberconstant  numberconstant whitespace numericconstant
whitespace ::= whitespacecharacter  whitespacecharacter whitespace
whitespacecharacter ::= ' '  TAB
TAB is ascii 9
numberconstant ::= arbitraryconstant  arbitraryconstant basetoken baseconstant
basetoken ::= 'b'  'b'
baseconstant ::= basedigits  basedigits '.' basedigits
basedigits ::= basedigit  basedigit basedigits
basedigit ::= digit  alpha1  alpha2
alpha1 ::= 'a''b''c''d''e''f''g''h''i''j''k''l''m'
alpha2 ::= 'n''o''p''q''r''s''t''u''v''w''x''y''z'
arbitraryconstant ::= complexconstant  piconstant  eulerconstant  extendedconstant
piconstant ::= complexconstant 'p' complexconstant
eulerconstant ::= complexconstant 'x' complexconstant
extendedconstant ::= signeddigits 'x'  signeddigits 'r' signeddigits
complexconstant ::= exponentialconstant  exponentialconstant complextoken exponentialconstant
complextoken ::= 'ad'  'ar'  'j'
exponentialconstant ::= signedconstant  signedconstant 'e' signedconstant
signedconstant ::= decimalconstant  '_' decimalconstant
decimalconstant ::= digits  digits '.' digits
signeddigits ::= 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)
ad, ar and j are used to describe complex numbers (angle in degrees, in radians, and rectangular form)
p and infix x are analogous to e except the base is pi or the base of natural logarithms
r and x are also used for arbitrary precision numbers, r indication a ration and a trailing x indicating an extended precision integer.
b is used for arbitrary bases, and letters az indicate digit values 10 through 35 when they follow a b
Floating point examples:
0 1 _2 3.4 3e4 3p4 3x4
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.
jq[edit]
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.0 => 1
1.2 => 1.2
1e10 => 10000000000
1e100 => 1e+100
1e1234 => 1.7976931348623157e+308
.1 => 0.1
.1e1 => 1
Java[edit]
1. //double equal to 1.0
1.0 //double
2432311.7567374 //double
1.234E10 //double
1.234e10 //double
758832d //double
728832f //float
1.0f //float
758832D //double
728832F //float
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.
Kotlin[edit]
val d: Double = 1.0
val d2: Double = 1.234e10
val f: Float = 728832f
val f2: Float = 728832F
Lasso[edit]
0.0
0.1
0.1
1.2e3
1.3e+3
1.2e3
Lingo[edit]
put 0.23
 0.2300
 activate higher printing precision
the floatPrecision = 8
put .23
 0.23000000
put 9.00719925474099e15
 9.00719925474099e15
 result is NOT a float
put 2/3
 0
 casting integer to float
put float(2)/3
 0.66666667
 casting string to float
put float("0.23")
 0.23000000
Lua[edit]
3.14159
314.159E2
Maple[edit]
Maple distinguishes "software floats" (of arbitrary precision) and "hardware floats" (of machine precision). To get the latter, use the "HFloat" constructor.
> 123.456; # decimal notation
123.456
> 1.23456e2; # scientific notation
123.456
> Float( 23, 2 ); # float constructor notation, by mantissa and exponent
0.23
> Float( .123456, 3 ); # again
123.456
> Float( 1.23456, 2 ); # again
123.456
> Float( 12.3456, 1 ); # again
123.456
> HFloat( 1.23456, 2 ); # hardware float constructor
123.456000000000
> HFloat( 123.456 ); # again
123.456000000000
> 2.3^30; # large floats are printed using scientific notation
11
0.7109434879 10
> 2/3; # NOT a float!
2/3
> evalf( 2/3 ); # but you can get one
0.6666666667
> 0.0; # zero
0.
> 0.0; # negative zero
0.
> Float(infinity); # positive infinity
Float(infinity)
> Float(infinity); # minus infinity
Float(infinity)
> Float(undefined); # "NaN", notanumber
Float(undefined)
Whether a given float is a software or hardware float can be determined by using "type".
> type( 2.3, 'hfloat' );
false
> type( HFloat( 2.3 ), 'hfloat' );
true
(There is also a type "sfloat" for software floats, and the type "float", which covers both.)
Mathematica[edit]
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}
{0.00049625,90458.4,4.06068*10^6}
This gives all numbers in scientific notation.
ScientificForm[%]
{4.9625*10^(4),9.04584*10^(4),4.06068*10^(6)}
This gives the numbers in engineering notation, with exponents arranged to be multiples of three.
EngineeringForm[%]
{496.25*10^(6),90.4584*10^(3),4.06068*10^(6)}
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.}
Maxima[edit]
/* Maxima has machine floating point (usually double precision IEEE 754), and
arbitrary length "big floats" */
/* Here are ordinary floats */
3.14159
2.718e0
1.2345d10
1.2345e10
1.2345f10
/* And big floats (always with a "b" for the exponent) */
3.14159b0
2.718b0
1.2345b10
/* Before computing with big float, one must set precision to some value (default is 16 decimal digits) */
fpprec: 40$
bfloat(%pi);
3.141592653589793238462643383279502884197b0
Nemerle[edit]
3.14f // float literal 3.14d, 3.14 // double literal 3.14m // decimal literal
Formally (from the Reference Manual):
<floating_point_literal> ::= [ <digits_> ] '.' <digits_> [ <exponent> ] [ <suffix> ]  <digits_> <exponent> [ <suffix> ]  <digits_> <suffix> <exponent> ::= <exponential_marker> [ <sign> ] <digits> <digits> ::= { <digit> } <digits_> ::= <digits> [ { '_' <digits> } ] <exponential_marker> ::= 'e'  'E' <sign> ::= '+'  '' <digit> ::= <decimal_digit> <suffix> ::= <floating_point_suffix> <floating_point_suffix> ::= 'f'  'd'  'm'
NetRexx[edit]
NetRexx supports decimal and exponential notation for floating point constants. A number in exponential notation is a simple number followed immediately by the sequence "E" (or "e"), followed immediately by a sign ("+" or ""), followed immediately by one or more digits.
NetRexx supports floating point number notation in the primitive float and double types, it's built in Rexx object and any other Java object that supports floating point numbers.
/* NetRexx */
options replace format comments java crossref symbols nobinary
numeric digits 40  make lots of space for big numbers
numeric form scientific  set output form for exponential notation
say 'Sample using objects of type "Rexx" (default):'
fv = 1.5; say '1.5'.right(20) '==' normalize(fv).right(20)  1.5
fv = 1.5; say '1.5'.right(20) '==' normalize(fv).right(20)  1.5
fv = 15e1; say '15e1'.right(20) '==' normalize(fv).right(20)  1.5
fv = 3e12; say '3e12'.right(20) '==' normalize(fv).right(20)  3E12
fv = 3e+12; say '3e+12'.right(20) '==' normalize(fv).right(20)  3000000000000
fv = 17.3E12; say '17.3E12'.right(20) '==' normalize(fv).right(20)  1.73E11
fv = 17.3E+12; say '17.3E+12'.right(20) '==' normalize(fv).right(20)  17300000000000
fv = 17.3E+40; say '17.3E+40'.right(20) '==' normalize(fv).right(20)  1.73E+41
fv = 0.033e+9; say '0.033e+9'.right(20) '==' normalize(fv).right(20)  33000000
fv = 0.033e9; say '0.033e9'.right(20) '==' normalize(fv).right(20)  3.3E11
say
say 'Sample using primitive type "float":'
ff = float
ff = float 15e1; say '15e1'.right(20) '==' normalize(ff).right(20)  1.5
ff = float 17.3E12; say '17.3E12'.right(20) '==' normalize(ff).right(20)  1.73E11
ff = float 17.3E+12; say '17.3E+12'.right(20) '==' normalize(ff).right(20)  17300000000000
ff = float 0.033E+9; say '0.033E+9'.right(20) '==' normalize(ff).right(20)  33000000
ff = float 0.033E9; say '0.033E9'.right(20) '==' normalize(ff).right(20)  3.3E11
say
say 'Sample using primitive type "double":'
fd = double
fd = 15e1; say '15e1'.right(20) '==' normalize(fd).right(20)  1.5
fd = 17.3E12; say '17.3E12'.right(20) '==' normalize(fd).right(20)  1.73E11
fd = 17.3E+12; say '17.3E+12'.right(20) '==' normalize(fd).right(20)  17300000000000
fd = 17.3E+40; say '17.3E+40'.right(20) '==' normalize(fd).right(20)  1.73E+41
fd = 0.033E+9; say '0.033E+9'.right(20) '==' normalize(fd).right(20)  33000000
fd = 0.033E9; say '0.033E9'.right(20) '==' normalize(fd).right(20)  3.3E11
say
return
/**
* Convert input to a Rexx object and add zero to the value which forces NetRexx to change its internal representation
*
* @param fv a Rexx object containing the floating point value
* @return a Rexx object which allows NetRexx string manipulation methods to act on it
*/
method normalize(fv) private constant
return fv + 0
Output:
Sample using objects of type "Rexx" (default): 1.5 == 1.5 1.5 == 1.5 15e1 == 1.5 3e12 == 3E12 3e+12 == 3000000000000 17.3E12 == 1.73E11 17.3E+12 == 17300000000000 17.3E+40 == 1.73E+41 0.033e+9 == 33000000 0.033e9 == 3.3E11 Sample using primitive type "float": 15e1 == 1.5 17.3E12 == 1.73E11 17.3E+12 == 17300000000000 0.033E+9 == 33000000 0.033E9 == 3.3E11 Sample using primitive type "double": 15e1 == 1.5 17.3E12 == 1.73E11 17.3E+12 == 17300000000000 17.3E+40 == 1.73E+41 0.033E+9 == 33000000 0.033E9 == 3.3E11
Nim[edit]
var x: float
x = 2.3
x = 2.0
x = 0.3
x = 123_456_789.000_000_1
x = 2e10
x = 2.5e10
x = 2.523_123E10
x = 5.2e10
var y = 2'f32 # Automatically a float32
var z = 2'f64 # Automatically a float64
Objeck[edit]
3 + .14159
3.14159
314.159E2
OCaml[edit]
In the OCaml manual, the chapter lexical conventions describes floatingpoint literals, which are:
floatliteral ::= [] (0…9) { 0…9∣ _ } [. { 0…9∣ _ }] [(e∣ E) [+∣ ] (0…9) { 0…9∣ _ }]
Here are some examples:
0.5
1.0
1. (* it is not possible to write only "1" because OCaml is strongly typed,
and this would be interpreted as an integer *)
1e10
3.14159_26535_89793
Oforth[edit]
A literal floating point number is written with a . and with or without an exponential notation :
3.14
1.0e12
0.13
1000.0
.22
PARI/GP[edit]
Similar to C, but allowing only decimal. Also, GP allows a trailing decimal point:
[+]?((\d*\.\d+\b)(\d+(\.\d*)?[Ee][+]?\d+\b)?(\.\d+[Ee][+]?\d+\b)(\d+\.))
PARI t_REAL numbers have a maximum value of
32bit  161,614,249 decimal digits  

64bit  694,127,911,065,419,642 decimal digits 
where is the machine epsilon at the selected precision. The minimum value is the opposite of the maximum value (reverse the sign bit).
Pascal[edit]
1.345 0.5345 5.34e34
Perl[edit]
# Standard notations:
.5;
0.5;
1.23345e10;
1.23445e10;
# The numbers can be grouped:
100_000_000; # equals to 100000000
Perl 6[edit]
Floating point numbers (the Num type) are written in the standard 'e' scientific notation:
2e2 # same as 200e0, 2e2, 200.0e0 and 2.0e2
6.02e23
2e48
1e9
1e0
A number like 3.1416 is specifically not floating point, but rational (the Rat type), equivalent to 3927/1250. On the other hand, Num(3.1416) would be considered a floating literal though by virtue of mandatory constant folding.
Phix[edit]
Phix does not require any distinction between integers and floats: 5 and 5.0 are exactly the same.
A variable declared as atom can hold an integer or a floating point value.
Division and other operators do what a sensible language should, eg 1/3 is 0.333333, not 0. [for the latter use floor(1/3)]
Floats cannot be expressed in any base other than decimal. They may optinally include a sign for mantissa and/or exponent.
It is not necessary for a digit to precede a decimal point, but one must follow it. Upper or lower e/g may be used.
In the 32bit version, integers outside 1,073,741,824 to +1,073,741,823 must be stored as atoms.
In the 64bit version the limits of integers are 4,611,686,018,427,387,904 to +4,611,686,018,427,387,903.
On a 32bit architecture floats can range from approximately 1e308 to +1e308 with 15 decimal digits,
and on a 64bit architecture they can range from approximately 1e4932 to +1e4932 with 19 decimal digits.
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
?1e+12  (same as 1e12)
?1e12
?5  (same as 5.0)
?1.  (illegal, use 1 or 1.0)
?.1  (same as 0.1)
?1/3  0.333333
printf(1,"%g %G\n",1e30)
 Output:
1e+12 1e12 5 0.1 0.3333333333 1e30 1E30
PHP[edit]
More information about floating point numbers in PHP.
.12
0.1234
1.2e3
7E10
Formal representation:
LNUM [09]+ DNUM ([09]*[\.]{LNUM})  ({LNUM}[\.][09]*) EXPONENT_DNUM [+]?(({LNUM}  {DNUM}) [eE][+]? {LNUM})
PicoLisp[edit]
PicoLisp does not support floating point literals in the base language, only fixed point (scaled) decimal integers of unlimited size and precision. See Numbers in the reference.
PL/I[edit]
1.2345e4 decimal floatingpoint
7e5 decimal floatingpoint
1.234_567_89e0 decimal floatingpoint.
1.0s0 decimal floatingpoint (single precision)
1.0d0 decimal floatingpoint (double precision)
1.34q0 decimal floatingpoint (quadruple/extended precision)
111.0101e7b binary floatingpoint equals 111.0101 * 2**7
or 7.3125 * 2**7
1e5b binary floatingpoint equals 1 * 2**5
PureBasic[edit]
Floating point literals do not need a decimal point if an exponent is used. They may also include a sign for the number or exponent.
1.0 1.0 1.0E2 1.0E+2 1.0E2 1E2
Python[edit]
This is an excerpt of an ANTLR grammar for python obtained from here.
FLOAT
: '.' DIGITS (Exponent)?
 DIGITS '.' Exponent
 DIGITS ('.' (DIGITS (Exponent)?)?  Exponent)
;
DIGITS : ( '0' .. '9' )+ ;
Exponent
: ('e'  'E') ( '+'  '' )? DIGITS
;
Examples
2.3 # 2.2999999999999998
.3 # 0.29999999999999999
.3e4 # 3000.0
.3e+34 # 2.9999999999999998e+33
.3e34 # 2.9999999999999999e35
2.e34 # 1.9999999999999999e+34
Racket[edit]
#lang racket
.2
2.
2.+0i ; zero imaginary part
2e0
#x10.8 ; hex float
#o1e2 ; oct float
2.0f0 ; single float
1.0t0 ; extended 80bit float (when available on platform)
Output:
0.2 2.0 2.0 2.0 16.5 64.0 2.0f0 1.0t0
REXX[edit]
All values in REXX are character strings, so a value could hold such things as these (decimal) numbers:
something = 127
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 builtin function format that can be used.
Note that a value of 0 (zero) in any form is always converted to
0
by the format BIF.
something = .00478
say something
say format(something,,,,0)
output
0.00478 4.78E3
The last invocation of format (above, with the 5th parameter equal to zero) forces exponential notation, unless the exponent is 0 (zero), then exponential notation won't be used.
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.
Ruby[edit]
A Float literal is an optional sign followed by one or more digits and a dot, one or more digits and an optional exponent (e or E followed by an optional sign and one or more digits). Unlike many languages .1 is not a valid float.
Underscores can be used for clarity: 1_000_000_000.01
Rust[edit]
2.3 // Normal floating point literal
3. // Equivalent to 3.0 (3 would be interpreted as an integer)
2f64 // The type (in this case f64, a 64bit floating point number) may be appended to the value
1_000.2_f32 // Underscores may appear anywhere in the number for clarity.<lang rust>
=={{headerScala}}==
{{libheaderScala}}
As all values in Scala, values are boxed with wrapper classes. The compiler will unbox them to primitive types for runtime execution.
<lang Scala>1. //Double equal to 1.0
1.0 //Double, a 64bit IEEE754 floating point number (equivalent to Java's double primitive type)
2432311.7567374 //Double
1.234E10 //Double
1.234e10 //Double
758832d //Double
728832f //32bit IEEE754 floating point number (equivalent to Java's float primitive type)
1.0f //Float
758832D //Double
728832F //Float
1.0F //Float
1 / 2. //Double
1 / 2 //Int equal to 0
// Constants
Float.MinPositiveValue
Float.NaN
Float.PositiveInfinity
Float.NegativeInfinity
Double.MinPositiveValue
Double.NaN
Double.PositiveInfinity
Double.NegativeInfinity
Values that are outside the bounds of a type will give compilertime errors when trying to force them to that type.
Scheme[edit]
.2 ; 0.2
2. ; 2.0
2e3 ; 2000
2.+3.i ; complex floatingpoint number
; in Scheme, floatingpoint numbers are inexact numbers
(inexact? 2.)
; #t
(inexact? 2)
; #f
Seed7[edit]
The type 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.0E12
0.1234
The functions str and the operators digits and parse create and accept float literals with sign.
Original source: [1]
Sidef[edit]
say 1.234;
say .1234;
say 1234e5;
say 12.34e5;
 Output:
1.234 0.1234 0.01234 1234000
Smalltalk[edit]
2.0
45e6
45e+6
78e9
1.2E34
base 2 mantissa:
2r1010.0 > 10.0
2r0.01 > 0.25
2r1010e5 > 320.0
base 2 mantissa and base 2 exponent:
2r1010e2r0101 > 320.0
Swift[edit]
let double = 1.0 as Double // Double precision
let float = 1.0 as Float // Single precision
let scientific = 1.0E12
// Swift does not feature type coercion for explicit type declaration
let sum = double + float // Error
let div = 1.1 / 2 // Double
let div1 = 1 / 2 // 0
Tcl[edit]
Floating point literals in Tcl always contain either “.” or “e” (of any case), if not both, or are references to either one of the IEEE infinities or NaN. Formally, they are values that (caseinsensitively) match one these regular expressions:
 Normal values
[+]?[09]*\.[09]+(e[+]?[09]+)?
[+]?[09]+\.?e[+]?[09]+
 Infinite values
[+]?inf(inity)?
 NaN values
[+]?nan(\([09af]+\))?
Note also that NaN values usually result in checked exceptions; they are supported mainly so that they can be handled when parsing and generating external binary data. All other floatingpoint literals are fully legal values. (Also note that this excludes the definition of integer literals; for details see this TIP document, which explains the whole state machine.)
Ursa[edit]
Cygnus/X Ursa (the standard Ursa interpreter) is written in Java and supports Java style floatingpoint literals.
1.
1.0
2432311.7567374
1.234E10
1.234e10
758832d
728832f
1.0f
758832D
728832F
1.0F
Vim Script[edit]
There are two ways to write floating point literals:

[+]?[09]+\.[09]+

[+]?[09]+\.[09]+[eE][+]?[09]+
Examples: 12.34 +0.34 1.0 12.34e5 0.99e2 1.0E+4
Note that there must always be at least one digit before and after the period (and for the exponent).
XPL0[edit]
0.
.1
1e3
123.456E300
123_456_789e+123
zkl[edit]
zkl requires something on both sides of the dot for a thing to be a float
1.0, 0.1, 3.1415, 1.e100, 1.2e100, 1e10, 1e+10, 123.456E300
 Programming Tasks
 Basic language learning
 Ada
 Aime
 ALGOL 68
 ALGOL W
 Applesoft BASIC
 AWK
 Axe
 BBC BASIC
 Bc
 C
 C sharp
 Clojure
 Common Lisp
 D
 Eiffel
 Elixir
 Erlang
 Euphoria
 Forth
 Fortran
 FreeBASIC
 GAP
 Gecho
 Go
 Groovy
 Haskell
 Icon
 Unicon
 Icon Programming Library
 J
 Jq
 Java
 Kotlin
 Lasso
 Lingo
 Lua
 Maple
 Mathematica
 Maxima
 Nemerle
 NetRexx
 Nim
 Objeck
 OCaml
 Oforth
 PARI/GP
 Pascal
 Perl
 Perl 6
 Phix
 PHP
 PicoLisp
 PL/I
 PureBasic
 Python
 Racket
 REXX
 Ruby
 Rust
 Scheme
 Seed7
 Sidef
 Smalltalk
 Swift
 Tcl
 Ursa
 Vim Script
 XPL0
 Zkl
 Integer BASIC/Omit
 ML/I/Omit
 Retro/Omit