|
GNU Emacs Lisp Reference Manual
3.2: Floating Point Basics
Emacs version 19 supports floating point numbers, if compiled with the macro LISP_FLOAT_TYPE defined. 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 in question.
The printed representation 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'.
Most modern computers support the IEEE floating point standard, which provides for 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, (sqrt -1.0) returns a NaN. For practical purposes, there's no significant difference between different NaN values in Emacs Lisp, and there's no rule for precisely which NaN value should be used in a particular case, so this manual doesn't try to distinguish them. Emacs Lisp has no read syntax for NaNs or infinities; perhaps we should create a syntax in the future.
You can use logb to extract the binary exponent of a floating point number (or estimate the logarithm of an integer):
- Function: logb number
- This function returns the binary exponent of number. More precisely, the value is the logarithm of number base 2, rounded down to an integer.
|