Next: , Previous: , Up: Numbers   [Contents][Index]


9.2 Floating Point Basics

SXEmacs supports floating point numbers. 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’.

Please bear in mind that floating point numbers have a limited and fixed precision although the printed output may suggest something else. The precision varies (depending on the machine) between 12 and 38 digits. Also note, that internally numbers are processed in a 2-adic arithmetic, hence some real numbers cannot be represented precisely and are rounded to the next precisely representable float instead.

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 SXEmacs 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. SXEmacs 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.


Next: , Previous: , Up: Numbers   [Contents][Index]