Next: Predicates on Numbers, Previous: Integer Basics, Up: Numbers

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
modern computers.

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
respect to `equal`

and `=`

), 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
example, `(log -1.0)`

typically returns a NaN, but on
non-IEEE platforms it returns an implementation-defined
value.

Here are the read syntaxes for these special floating point values:

- positive infinity
- ‘
`1.0e+INF`’ - negative infinity
- ‘
`-1.0e+INF`’ - Not-a-number
- ‘
`0.0e+NaN`’ or ‘`-0.0e+NaN`’.

— Function: **isnan**` number`

This predicate tests whether its argument is NaN, and returns

`t`

if so,`nil`

otherwise. The argument must be a number.

The following functions are specialized for handling floating point numbers:

— Function: **frexp**` x`

This function returns a cons cell

`(`

sig`.`

exp`)`

, wheresigandexpare respectively the significand and exponent of the floating point numberx:x=sig* 2^exp

sigis a floating point number between 0.5 (inclusive) and 1.0 (exclusive). Ifxis zero, the return value is`(0 . 0)`

.

— Function: **ldexp**` sig &optional exp`

This function returns a floating point number corresponding to the significand

sigand exponentexp.