Floating point numbers are useful for representing numbers that are
not integral. The precise range of floating point numbers is
machine-specific; it is the same as the range of the C data type
double on the machine you are using. Emacs uses the
IEEE floating point standard, which is supported by all
The read syntax for floating point numbers requires either a decimal point (with at least one digit following), an exponent, or both. For example, ‘1500.0’, ‘15e2’, ‘15.0e2’, ‘1.5e3’, and ‘.15e4’ are five ways of writing a floating point number whose value is 1500. They are all equivalent. You can also use a minus sign to write negative floating point numbers, as in ‘-1.0’.
Emacs Lisp treats
-0.0 as equal to ordinary zero (with
=), even though the two are
distinguishable in the IEEE floating point standard.
The IEEE floating point standard supports positive
infinity and negative infinity as floating point values. It also
provides for a class of values called NaN or “not-a-number”;
numerical functions return such values in cases where there is no
correct answer. For example,
(/ 0.0 0.0) returns a NaN. (NaN
values can also carry a sign, but for practical purposes there's no
significant difference between different NaN values in Emacs Lisp.)
When a function is documented to return a NaN, it returns an
implementation-defined value when Emacs is running on one of the
now-rare platforms that do not use IEEE floating point. For
(log -1.0) typically returns a NaN, but on
non-IEEE platforms it returns an implementation-defined
Here are the read syntaxes for these special floating point values:
This predicate tests whether its argument is NaN, and returns
nilotherwise. The argument must be a number.
The following functions are specialized for handling floating point numbers:
This function returns a cons cell
), where sig and exp are respectively the significand and exponent of the floating point number x:x = sig * 2^exp
sig is a floating point number between 0.5 (inclusive) and 1.0 (exclusive). If x is zero, the return value is
(0 . 0).
This function returns a floating point number corresponding to the significand sig and exponent exp.
This function copies the sign of x2 to the value of x1, and returns the result. x1 and x2 must be floating point numbers.