aboutsummaryrefslogtreecommitdiffstats
path: root/doc
diff options
context:
space:
mode:
authorPaul Eggert2012-09-10 19:28:27 -0700
committerPaul Eggert2012-09-10 19:28:27 -0700
commitc990426a9883c1bd1782e6b117184b654eecda67 (patch)
tree43083f890e5286637ee754482af0f92d6d2236d0 /doc
parent6fda35f2b3e3ce3c7dcc05f230f60c51c4c42e60 (diff)
downloademacs-c990426a9883c1bd1782e6b117184b654eecda67.tar.gz
emacs-c990426a9883c1bd1782e6b117184b654eecda67.zip
Simplify, document, and port floating-point.
The porting part of this patch fixes bugs on non-IEEE platforms with frexp, ldexp, logb. * admin/CPP-DEFINES (HAVE_CBRT, HAVE_LOGB, logb): Remove. * configure.ac (logb, cbrt): Do not check for these functions, as they are not being used. * doc/lispref/numbers.texi (Float Basics, Arithmetic Operations, Math Functions): Document that / and mod (with floating point arguments), along with asin, acos, log, log10, expt and sqrt, return special values instead of signaling exceptions. (Float Basics): Document that logb operates on the absolute value of its argument. (Math Functions): Document that (log ARG BASE) also returns NaN if BASE is negative. Document that (expt X Y) returns NaN if X is a finite negative number and Y a finite non-integer. * etc/NEWS: Document NaNs versus signaling-error change. * src/data.c, src/lisp.h (Qdomain_error, Qsingularity_error, Qunderflow_error): Now static. * src/floatfns.c: Simplify discussion of functions that Emacs doesn't support, by removing commented-out code and briefly listing the C89 functions excluded. The commented-out stuff was confusing maintenance, e.g., we thought we needed cbrt but it was commented out. (logb): Remove decl; no longer needed. (isfinite): New macro, if not already supplied. (isnan): Don't replace any existing macro. (Ffrexp, Fldexp): Define even if !HAVE_COPYSIGN, as frexp and ldexp are present on all C89 platforms. (Ffrexp): Do not special-case zero, as frexp does the right thing for that case. (Flogb): Do not use logb, as it doesn't have the desired meaning on hosts that use non-base-2 floating point. Instead, stick with frexp, which is C89 anyway. Do not pass an infinity or a NaN to frexp, to avoid getting an unspecified result.
Diffstat (limited to 'doc')
-rw-r--r--doc/lispref/ChangeLog13
-rw-r--r--doc/lispref/numbers.texi35
2 files changed, 35 insertions, 13 deletions
diff --git a/doc/lispref/ChangeLog b/doc/lispref/ChangeLog
index ceb199dae88..ce99c81a912 100644
--- a/doc/lispref/ChangeLog
+++ b/doc/lispref/ChangeLog
@@ -1,3 +1,16 @@
12012-09-11 Paul Eggert <eggert@cs.ucla.edu>
2
3 Simplify, document, and port floating-point (Bug#12381).
4 * numbers.texi (Float Basics, Arithmetic Operations, Math Functions):
5 Document that / and mod (with floating point arguments), along
6 with asin, acos, log, log10, expt and sqrt, return special values
7 instead of signaling exceptions.
8 (Float Basics): Document that logb operates on the absolute value
9 of its argument.
10 (Math Functions): Document that (log ARG BASE) also returns NaN if
11 BASE is negative. Document that (expt X Y) returns NaN if X is a
12 finite negative number and Y a finite non-integer.
13
12012-09-09 Chong Yidong <cyd@gnu.org> 142012-09-09 Chong Yidong <cyd@gnu.org>
2 15
3 * lists.texi (Sets And Lists): Explain that the return value for 16 * lists.texi (Sets And Lists): Explain that the return value for
diff --git a/doc/lispref/numbers.texi b/doc/lispref/numbers.texi
index 17f3ee099bd..7c9672a38c0 100644
--- a/doc/lispref/numbers.texi
+++ b/doc/lispref/numbers.texi
@@ -196,6 +196,14 @@ numerical functions return such values in cases where there is no
196correct answer. For example, @code{(/ 0.0 0.0)} returns a NaN. (NaN 196correct answer. For example, @code{(/ 0.0 0.0)} returns a NaN. (NaN
197values can also carry a sign, but for practical purposes there's no 197values can also carry a sign, but for practical purposes there's no
198significant difference between different NaN values in Emacs Lisp.) 198significant difference between different NaN values in Emacs Lisp.)
199
200When a function is documented to return a NaN, it returns an
201implementation-defined value when Emacs is running on one of the
202now-rare platforms that do not use @acronym{IEEE} floating point. For
203example, @code{(log -1.0)} typically returns a NaN, but on
204non-@acronym{IEEE} platforms it returns an implementation-defined
205value.
206
199Here are the read syntaxes for these special floating point values: 207Here are the read syntaxes for these special floating point values:
200 208
201@table @asis 209@table @asis
@@ -241,7 +249,7 @@ numbers.
241 249
242@defun logb number 250@defun logb number
243This function returns the binary exponent of @var{number}. More 251This function returns the binary exponent of @var{number}. More
244precisely, the value is the logarithm of @var{number} base 2, rounded 252precisely, the value is the logarithm of |@var{number}| base 2, rounded
245down to an integer. 253down to an integer.
246 254
247@example 255@example
@@ -694,7 +702,8 @@ arguments. It also permits floating point arguments; it rounds the
694quotient downward (towards minus infinity) to an integer, and uses that 702quotient downward (towards minus infinity) to an integer, and uses that
695quotient to compute the remainder. 703quotient to compute the remainder.
696 704
697An @code{arith-error} results if @var{divisor} is 0. 705If @var{divisor} is zero, @code{mod} signals an @code{arith-error}
706error if both arguments are integers, and returns a NaN otherwise.
698 707
699@example 708@example
700@group 709@group
@@ -1096,8 +1105,8 @@ pi/2
1096@tex 1105@tex
1097@math{\pi/2} 1106@math{\pi/2}
1098@end tex 1107@end tex
1099(inclusive) whose sine is @var{arg}; if, however, @var{arg} is out of 1108(inclusive) whose sine is @var{arg}. If @var{arg} is out of range
1100range (outside [@minus{}1, 1]), it signals a @code{domain-error} error. 1109(outside [@minus{}1, 1]), @code{asin} returns a NaN.
1101@end defun 1110@end defun
1102 1111
1103@defun acos arg 1112@defun acos arg
@@ -1108,8 +1117,8 @@ pi
1108@tex 1117@tex
1109@math{\pi} 1118@math{\pi}
1110@end tex 1119@end tex
1111(inclusive) whose cosine is @var{arg}; if, however, @var{arg} is out 1120(inclusive) whose cosine is @var{arg}. If @var{arg} is out of range
1112of range (outside [@minus{}1, 1]), it signals a @code{domain-error} error. 1121(outside [@minus{}1, 1]), @code{acos} returns a NaN.
1113@end defun 1122@end defun
1114 1123
1115@defun atan y &optional x 1124@defun atan y &optional x
@@ -1141,8 +1150,8 @@ This is the exponential function; it returns @math{e} to the power
1141@defun log arg &optional base 1150@defun log arg &optional base
1142This function returns the logarithm of @var{arg}, with base 1151This function returns the logarithm of @var{arg}, with base
1143@var{base}. If you don't specify @var{base}, the natural base 1152@var{base}. If you don't specify @var{base}, the natural base
1144@math{e} is used. If @var{arg} is negative, it signals a 1153@math{e} is used. If @var{arg} or @var{base} is negative, @code{log}
1145@code{domain-error} error. 1154returns a NaN.
1146@end defun 1155@end defun
1147 1156
1148@ignore 1157@ignore
@@ -1160,21 +1169,21 @@ lose accuracy.
1160@end ignore 1169@end ignore
1161 1170
1162@defun log10 arg 1171@defun log10 arg
1163This function returns the logarithm of @var{arg}, with base 10. If 1172This function returns the logarithm of @var{arg}, with base 10:
1164@var{arg} is negative, it signals a @code{domain-error} error. 1173@code{(log10 @var{x})} @equiv{} @code{(log @var{x} 10)}.
1165@code{(log10 @var{x})} @equiv{} @code{(log @var{x} 10)}, at least
1166approximately.
1167@end defun 1174@end defun
1168 1175
1169@defun expt x y 1176@defun expt x y
1170This function returns @var{x} raised to power @var{y}. If both 1177This function returns @var{x} raised to power @var{y}. If both
1171arguments are integers and @var{y} is positive, the result is an 1178arguments are integers and @var{y} is positive, the result is an
1172integer; in this case, overflow causes truncation, so watch out. 1179integer; in this case, overflow causes truncation, so watch out.
1180If @var{x} is a finite negative number and @var{y} is a finite
1181non-integer, @code{expt} returns a NaN.
1173@end defun 1182@end defun
1174 1183
1175@defun sqrt arg 1184@defun sqrt arg
1176This returns the square root of @var{arg}. If @var{arg} is negative, 1185This returns the square root of @var{arg}. If @var{arg} is negative,
1177it signals a @code{domain-error} error. 1186@code{sqrt} returns a NaN.
1178@end defun 1187@end defun
1179 1188
1180In addition, Emacs defines the following common mathematical 1189In addition, Emacs defines the following common mathematical