diff options
| author | Paul Eggert | 2012-09-10 19:28:27 -0700 |
|---|---|---|
| committer | Paul Eggert | 2012-09-10 19:28:27 -0700 |
| commit | c990426a9883c1bd1782e6b117184b654eecda67 (patch) | |
| tree | 43083f890e5286637ee754482af0f92d6d2236d0 | |
| parent | 6fda35f2b3e3ce3c7dcc05f230f60c51c4c42e60 (diff) | |
| download | emacs-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.
| -rw-r--r-- | ChangeLog | 6 | ||||
| -rw-r--r-- | admin/CPP-DEFINES | 4 | ||||
| -rw-r--r-- | admin/ChangeLog | 5 | ||||
| -rw-r--r-- | configure.ac | 6 | ||||
| -rw-r--r-- | doc/lispref/ChangeLog | 13 | ||||
| -rw-r--r-- | doc/lispref/numbers.texi | 35 | ||||
| -rw-r--r-- | etc/ChangeLog | 5 | ||||
| -rw-r--r-- | etc/NEWS | 8 | ||||
| -rw-r--r-- | src/ChangeLog | 21 | ||||
| -rw-r--r-- | src/data.c | 4 | ||||
| -rw-r--r-- | src/floatfns.c | 231 | ||||
| -rw-r--r-- | src/lisp.h | 3 |
12 files changed, 105 insertions, 236 deletions
| @@ -1,3 +1,9 @@ | |||
| 1 | 2012-09-11 Paul Eggert <eggert@cs.ucla.edu> | ||
| 2 | |||
| 3 | Simplify, document, and port floating-point (Bug#12381). | ||
| 4 | * configure.ac (logb, cbrt): Do not check for these functions, | ||
| 5 | as they are not being used. | ||
| 6 | |||
| 1 | 2012-09-10 Paul Eggert <eggert@cs.ucla.edu> | 7 | 2012-09-10 Paul Eggert <eggert@cs.ucla.edu> |
| 2 | 8 | ||
| 3 | Improve robustness of 'make bootstrap' (Bug#12376). | 9 | Improve robustness of 'make bootstrap' (Bug#12376). |
diff --git a/admin/CPP-DEFINES b/admin/CPP-DEFINES index b40ba78e20d..cf6ffee2c63 100644 --- a/admin/CPP-DEFINES +++ b/admin/CPP-DEFINES | |||
| @@ -120,7 +120,6 @@ HAVE_ATTRIBUTE_ALIGNED | |||
| 120 | HAVE_BDFFONT | 120 | HAVE_BDFFONT |
| 121 | HAVE_BOXES | 121 | HAVE_BOXES |
| 122 | HAVE_C99_STRTOLD | 122 | HAVE_C99_STRTOLD |
| 123 | HAVE_CBRT | ||
| 124 | HAVE_CFMAKERAW | 123 | HAVE_CFMAKERAW |
| 125 | HAVE_CFSETSPEED | 124 | HAVE_CFSETSPEED |
| 126 | HAVE_CLOCK_GETTIME | 125 | HAVE_CLOCK_GETTIME |
| @@ -251,7 +250,6 @@ HAVE_LIBXMU | |||
| 251 | HAVE_LINUX_VERSION_H | 250 | HAVE_LINUX_VERSION_H |
| 252 | HAVE_LOCALTIME_R | 251 | HAVE_LOCALTIME_R |
| 253 | HAVE_LOCAL_SOCKETS | 252 | HAVE_LOCAL_SOCKETS |
| 254 | HAVE_LOGB | ||
| 255 | HAVE_LONG_FILE_NAMES | 253 | HAVE_LONG_FILE_NAMES |
| 256 | HAVE_LONG_LONG_INT | 254 | HAVE_LONG_LONG_INT |
| 257 | HAVE_LRAND48 | 255 | HAVE_LRAND48 |
| @@ -574,7 +572,6 @@ getpid | |||
| 574 | isatty | 572 | isatty |
| 575 | kill | 573 | kill |
| 576 | link | 574 | link |
| 577 | logb | ||
| 578 | lseek | 575 | lseek |
| 579 | mkdir | 576 | mkdir |
| 580 | mktemp | 577 | mktemp |
| @@ -616,7 +613,6 @@ fopen | |||
| 616 | getpid | 613 | getpid |
| 617 | index | 614 | index |
| 618 | isatty | 615 | isatty |
| 619 | logb | ||
| 620 | lseek | 616 | lseek |
| 621 | mkdir | 617 | mkdir |
| 622 | mktemp | 618 | mktemp |
diff --git a/admin/ChangeLog b/admin/ChangeLog index 2c61f437981..b70067d7465 100644 --- a/admin/ChangeLog +++ b/admin/ChangeLog | |||
| @@ -1,3 +1,8 @@ | |||
| 1 | 2012-09-11 Paul Eggert <eggert@cs.ucla.edu> | ||
| 2 | |||
| 3 | Simplify, document, and port floating-point (Bug#12381). | ||
| 4 | * CPP-DEFINES (HAVE_CBRT, HAVE_LOGB, logb): Remove. | ||
| 5 | |||
| 1 | 2012-09-09 Paul Eggert <eggert@cs.ucla.edu> | 6 | 2012-09-09 Paul Eggert <eggert@cs.ucla.edu> |
| 2 | 7 | ||
| 3 | Assume C89 or later for math functions (Bug#12381). | 8 | Assume C89 or later for math functions (Bug#12381). |
diff --git a/configure.ac b/configure.ac index 97e967d8043..9491c1da8d5 100644 --- a/configure.ac +++ b/configure.ac | |||
| @@ -2689,8 +2689,8 @@ if test $emacs_cv_netdb_declares_h_errno = yes; then | |||
| 2689 | AC_DEFINE(HAVE_H_ERRNO, 1, [Define to 1 if netdb.h declares h_errno.]) | 2689 | AC_DEFINE(HAVE_H_ERRNO, 1, [Define to 1 if netdb.h declares h_errno.]) |
| 2690 | fi | 2690 | fi |
| 2691 | 2691 | ||
| 2692 | # fmod, logb, and frexp are found in -lm on most systems. | 2692 | # sqrt and other floating-point functions such as fmod and frexp |
| 2693 | # On HPUX 9.01, -lm does not contain logb, so check for sqrt. | 2693 | # are found in -lm on most systems. |
| 2694 | AC_CHECK_LIB(m, sqrt) | 2694 | AC_CHECK_LIB(m, sqrt) |
| 2695 | 2695 | ||
| 2696 | # Check for mail-locking functions in a "mail" library. Probably this should | 2696 | # Check for mail-locking functions in a "mail" library. Probably this should |
| @@ -2770,7 +2770,7 @@ AC_SUBST(BLESSMAIL_TARGET) | |||
| 2770 | 2770 | ||
| 2771 | AC_CHECK_FUNCS(gethostname \ | 2771 | AC_CHECK_FUNCS(gethostname \ |
| 2772 | closedir getrusage get_current_dir_name \ | 2772 | closedir getrusage get_current_dir_name \ |
| 2773 | lrand48 logb cbrt setsid \ | 2773 | lrand48 setsid \ |
| 2774 | fpathconf select euidaccess getpagesize setlocale \ | 2774 | fpathconf select euidaccess getpagesize setlocale \ |
| 2775 | utimes getrlimit setrlimit setpgid getcwd shutdown getaddrinfo \ | 2775 | utimes getrlimit setrlimit setpgid getcwd shutdown getaddrinfo \ |
| 2776 | __fpending strsignal setitimer \ | 2776 | __fpending strsignal setitimer \ |
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 @@ | |||
| 1 | 2012-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 | |||
| 1 | 2012-09-09 Chong Yidong <cyd@gnu.org> | 14 | 2012-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 | |||
| 196 | correct answer. For example, @code{(/ 0.0 0.0)} returns a NaN. (NaN | 196 | correct answer. For example, @code{(/ 0.0 0.0)} returns a NaN. (NaN |
| 197 | values can also carry a sign, but for practical purposes there's no | 197 | values can also carry a sign, but for practical purposes there's no |
| 198 | significant difference between different NaN values in Emacs Lisp.) | 198 | significant difference between different NaN values in Emacs Lisp.) |
| 199 | |||
| 200 | When a function is documented to return a NaN, it returns an | ||
| 201 | implementation-defined value when Emacs is running on one of the | ||
| 202 | now-rare platforms that do not use @acronym{IEEE} floating point. For | ||
| 203 | example, @code{(log -1.0)} typically returns a NaN, but on | ||
| 204 | non-@acronym{IEEE} platforms it returns an implementation-defined | ||
| 205 | value. | ||
| 206 | |||
| 199 | Here are the read syntaxes for these special floating point values: | 207 | Here 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 |
| 243 | This function returns the binary exponent of @var{number}. More | 251 | This function returns the binary exponent of @var{number}. More |
| 244 | precisely, the value is the logarithm of @var{number} base 2, rounded | 252 | precisely, the value is the logarithm of |@var{number}| base 2, rounded |
| 245 | down to an integer. | 253 | down to an integer. |
| 246 | 254 | ||
| 247 | @example | 255 | @example |
| @@ -694,7 +702,8 @@ arguments. It also permits floating point arguments; it rounds the | |||
| 694 | quotient downward (towards minus infinity) to an integer, and uses that | 702 | quotient downward (towards minus infinity) to an integer, and uses that |
| 695 | quotient to compute the remainder. | 703 | quotient to compute the remainder. |
| 696 | 704 | ||
| 697 | An @code{arith-error} results if @var{divisor} is 0. | 705 | If @var{divisor} is zero, @code{mod} signals an @code{arith-error} |
| 706 | error 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 |
| 1100 | range (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 |
| 1112 | of 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 |
| 1142 | This function returns the logarithm of @var{arg}, with base | 1151 | This 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. | 1154 | returns 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 |
| 1163 | This function returns the logarithm of @var{arg}, with base 10. If | 1172 | This 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 | ||
| 1166 | approximately. | ||
| 1167 | @end defun | 1174 | @end defun |
| 1168 | 1175 | ||
| 1169 | @defun expt x y | 1176 | @defun expt x y |
| 1170 | This function returns @var{x} raised to power @var{y}. If both | 1177 | This function returns @var{x} raised to power @var{y}. If both |
| 1171 | arguments are integers and @var{y} is positive, the result is an | 1178 | arguments are integers and @var{y} is positive, the result is an |
| 1172 | integer; in this case, overflow causes truncation, so watch out. | 1179 | integer; in this case, overflow causes truncation, so watch out. |
| 1180 | If @var{x} is a finite negative number and @var{y} is a finite | ||
| 1181 | non-integer, @code{expt} returns a NaN. | ||
| 1173 | @end defun | 1182 | @end defun |
| 1174 | 1183 | ||
| 1175 | @defun sqrt arg | 1184 | @defun sqrt arg |
| 1176 | This returns the square root of @var{arg}. If @var{arg} is negative, | 1185 | This returns the square root of @var{arg}. If @var{arg} is negative, |
| 1177 | it signals a @code{domain-error} error. | 1186 | @code{sqrt} returns a NaN. |
| 1178 | @end defun | 1187 | @end defun |
| 1179 | 1188 | ||
| 1180 | In addition, Emacs defines the following common mathematical | 1189 | In addition, Emacs defines the following common mathematical |
diff --git a/etc/ChangeLog b/etc/ChangeLog index aa788275256..11e7e5ca108 100644 --- a/etc/ChangeLog +++ b/etc/ChangeLog | |||
| @@ -1,3 +1,8 @@ | |||
| 1 | 2012-09-11 Paul Eggert <eggert@cs.ucla.edu> | ||
| 2 | |||
| 3 | Simplify, document, and port floating-point (Bug#12381). | ||
| 4 | * NEWS: Document NaNs versus signaling-error change. | ||
| 5 | |||
| 1 | 2012-09-04 Paul Eggert <eggert@cs.ucla.edu> | 6 | 2012-09-04 Paul Eggert <eggert@cs.ucla.edu> |
| 2 | 7 | ||
| 3 | Give more-useful info on a fatal error (Bug#12328). | 8 | Give more-useful info on a fatal error (Bug#12328). |
| @@ -729,6 +729,14 @@ table, but with a different prefix. | |||
| 729 | must be in the range 1000..9999. It now works with any year supported | 729 | must be in the range 1000..9999. It now works with any year supported |
| 730 | by the underlying C implementation. | 730 | by the underlying C implementation. |
| 731 | 731 | ||
| 732 | ** Floating point | ||
| 733 | |||
| 734 | *** When floating point functions such as `log' are given invalid | ||
| 735 | arguments, e.g., (log -1.0), they now uniformly return special values | ||
| 736 | such as NaNs instead of signaling errors. Previously, these functions | ||
| 737 | returned NaNs on some platforms but signaled errors on others. The affected | ||
| 738 | functions are acos, asin, tan, exp, expt, log, log10, sqrt, and mod. | ||
| 739 | |||
| 732 | ** New function file-name-base. | 740 | ** New function file-name-base. |
| 733 | 741 | ||
| 734 | ** New function `tty-top-frame' returns the topmost frame of a text terminal. | 742 | ** New function `tty-top-frame' returns the topmost frame of a text terminal. |
diff --git a/src/ChangeLog b/src/ChangeLog index 4eda17da3a7..0e5bbfd2524 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,5 +1,26 @@ | |||
| 1 | 2012-09-11 Paul Eggert <eggert@cs.ucla.edu> | 1 | 2012-09-11 Paul Eggert <eggert@cs.ucla.edu> |
| 2 | 2 | ||
| 3 | Simplify, document, and port floating-point (Bug#12381). | ||
| 4 | The porting part of this patch fixes bugs on non-IEEE platforms | ||
| 5 | with frexp, ldexp, logb. | ||
| 6 | * data.c, lisp.h (Qdomain_error, Qsingularity_error, Qunderflow_error): | ||
| 7 | Now static. | ||
| 8 | * floatfns.c: Simplify discussion of functions that Emacs doesn't | ||
| 9 | support, by removing commented-out code and briefly listing the | ||
| 10 | C89 functions excluded. The commented-out stuff was confusing | ||
| 11 | maintenance, e.g., we thought we needed cbrt but it was commented out. | ||
| 12 | (logb): Remove decl; no longer needed. | ||
| 13 | (isfinite): New macro, if not already supplied. | ||
| 14 | (isnan): Don't replace any existing macro. | ||
| 15 | (Ffrexp, Fldexp): Define even if !HAVE_COPYSIGN, as frexp and ldexp | ||
| 16 | are present on all C89 platforms. | ||
| 17 | (Ffrexp): Do not special-case zero, as frexp does the right thing | ||
| 18 | for that case. | ||
| 19 | (Flogb): Do not use logb, as it doesn't have the desired meaning | ||
| 20 | on hosts that use non-base-2 floating point. Instead, stick with | ||
| 21 | frexp, which is C89 anyway. Do not pass an infinity or a NaN to | ||
| 22 | frexp, to avoid getting an unspecified result. | ||
| 23 | |||
| 3 | * xdisp.c (Qinhibit_debug_on_message): Now static. | 24 | * xdisp.c (Qinhibit_debug_on_message): Now static. |
| 4 | 25 | ||
| 5 | 2012-09-10 Jan Djärv <jan.h.d@swipnet.se> | 26 | 2012-09-10 Jan Djärv <jan.h.d@swipnet.se> |
diff --git a/src/data.c b/src/data.c index a4cca0a3ee5..4678ac1208c 100644 --- a/src/data.c +++ b/src/data.c | |||
| @@ -71,8 +71,8 @@ Lisp_Object Qchar_table_p, Qvector_or_char_table_p; | |||
| 71 | Lisp_Object Qcdr; | 71 | Lisp_Object Qcdr; |
| 72 | static Lisp_Object Qad_advice_info, Qad_activate_internal; | 72 | static Lisp_Object Qad_advice_info, Qad_activate_internal; |
| 73 | 73 | ||
| 74 | Lisp_Object Qrange_error, Qdomain_error, Qsingularity_error; | 74 | static Lisp_Object Qdomain_error, Qsingularity_error, Qunderflow_error; |
| 75 | Lisp_Object Qoverflow_error, Qunderflow_error; | 75 | Lisp_Object Qrange_error, Qoverflow_error; |
| 76 | 76 | ||
| 77 | Lisp_Object Qfloatp; | 77 | Lisp_Object Qfloatp; |
| 78 | Lisp_Object Qnumberp, Qnumber_or_marker_p; | 78 | Lisp_Object Qnumberp, Qnumber_or_marker_p; |
diff --git a/src/floatfns.c b/src/floatfns.c index 8a9a9fd0886..66d7ca4af2c 100644 --- a/src/floatfns.c +++ b/src/floatfns.c | |||
| @@ -22,9 +22,10 @@ You should have received a copy of the GNU General Public License | |||
| 22 | along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | 22 | along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ |
| 23 | 23 | ||
| 24 | 24 | ||
| 25 | /* C89 requires only these math.h functions: | 25 | /* C89 requires only the following math.h functions, and Emacs omits |
| 26 | acos, asin, atan, atan2, ceil, cos, cosh, exp, fabs, floor, fmod, | 26 | the starred functions since we haven't found a use for them: |
| 27 | frexp, ldexp, log, log10, modf, pow, sin, sinh, sqrt, tan, tanh. | 27 | acos, asin, atan, atan2, ceil, cos, *cosh, exp, fabs, floor, fmod, |
| 28 | frexp, ldexp, log, log10, *modf, pow, sin, *sinh, sqrt, tan, *tanh. | ||
| 28 | */ | 29 | */ |
| 29 | 30 | ||
| 30 | #include <config.h> | 31 | #include <config.h> |
| @@ -42,10 +43,12 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 42 | 43 | ||
| 43 | #include <math.h> | 44 | #include <math.h> |
| 44 | 45 | ||
| 45 | /* This declaration is omitted on some systems, like Ultrix. */ | 46 | #ifndef isfinite |
| 46 | #if !defined (HPUX) && defined (HAVE_LOGB) && !defined (logb) | 47 | # define isfinite(x) ((x) - (x) == 0) |
| 47 | extern double logb (double); | 48 | #endif |
| 48 | #endif /* not HPUX and HAVE_LOGB and no logb macro */ | 49 | #ifndef isnan |
| 50 | # define isnan(x) ((x) != (x)) | ||
| 51 | #endif | ||
| 49 | 52 | ||
| 50 | /* Extract a Lisp number as a `double', or signal an error. */ | 53 | /* Extract a Lisp number as a `double', or signal an error. */ |
| 51 | 54 | ||
| @@ -126,9 +129,6 @@ DEFUN ("tan", Ftan, Stan, 1, 1, 0, | |||
| 126 | return make_float (d); | 129 | return make_float (d); |
| 127 | } | 130 | } |
| 128 | 131 | ||
| 129 | #undef isnan | ||
| 130 | #define isnan(x) ((x) != (x)) | ||
| 131 | |||
| 132 | DEFUN ("isnan", Fisnan, Sisnan, 1, 1, 0, | 132 | DEFUN ("isnan", Fisnan, Sisnan, 1, 1, 0, |
| 133 | doc: /* Return non nil iff argument X is a NaN. */) | 133 | doc: /* Return non nil iff argument X is a NaN. */) |
| 134 | (Lisp_Object x) | 134 | (Lisp_Object x) |
| @@ -153,6 +153,7 @@ Cause an error if X1 or X2 is not a float. */) | |||
| 153 | 153 | ||
| 154 | return make_float (copysign (f1, f2)); | 154 | return make_float (copysign (f1, f2)); |
| 155 | } | 155 | } |
| 156 | #endif | ||
| 156 | 157 | ||
| 157 | DEFUN ("frexp", Ffrexp, Sfrexp, 1, 1, 0, | 158 | DEFUN ("frexp", Ffrexp, Sfrexp, 1, 1, 0, |
| 158 | doc: /* Get significand and exponent of a floating point number. | 159 | doc: /* Get significand and exponent of a floating point number. |
| @@ -167,15 +168,9 @@ If X is zero, both parts (SGNFCAND and EXP) are zero. */) | |||
| 167 | (Lisp_Object x) | 168 | (Lisp_Object x) |
| 168 | { | 169 | { |
| 169 | double f = XFLOATINT (x); | 170 | double f = XFLOATINT (x); |
| 170 | 171 | int exponent; | |
| 171 | if (f == 0.0) | 172 | double sgnfcand = frexp (f, &exponent); |
| 172 | return Fcons (make_float (0.0), make_number (0)); | 173 | return Fcons (make_float (sgnfcand), make_number (exponent)); |
| 173 | else | ||
| 174 | { | ||
| 175 | int exponent; | ||
| 176 | double sgnfcand = frexp (f, &exponent); | ||
| 177 | return Fcons (make_float (sgnfcand), make_number (exponent)); | ||
| 178 | } | ||
| 179 | } | 174 | } |
| 180 | 175 | ||
| 181 | DEFUN ("ldexp", Fldexp, Sldexp, 1, 2, 0, | 176 | DEFUN ("ldexp", Fldexp, Sldexp, 1, 2, 0, |
| @@ -187,118 +182,6 @@ Returns the floating point value resulting from multiplying SGNFCAND | |||
| 187 | CHECK_NUMBER (exponent); | 182 | CHECK_NUMBER (exponent); |
| 188 | return make_float (ldexp (XFLOATINT (sgnfcand), XINT (exponent))); | 183 | return make_float (ldexp (XFLOATINT (sgnfcand), XINT (exponent))); |
| 189 | } | 184 | } |
| 190 | #endif | ||
| 191 | |||
| 192 | #if 0 /* Leave these out unless we find there's a reason for them. */ | ||
| 193 | |||
| 194 | DEFUN ("bessel-j0", Fbessel_j0, Sbessel_j0, 1, 1, 0, | ||
| 195 | doc: /* Return the bessel function j0 of ARG. */) | ||
| 196 | (Lisp_Object arg) | ||
| 197 | { | ||
| 198 | double d = extract_float (arg); | ||
| 199 | d = j0 (d); | ||
| 200 | return make_float (d); | ||
| 201 | } | ||
| 202 | |||
| 203 | DEFUN ("bessel-j1", Fbessel_j1, Sbessel_j1, 1, 1, 0, | ||
| 204 | doc: /* Return the bessel function j1 of ARG. */) | ||
| 205 | (Lisp_Object arg) | ||
| 206 | { | ||
| 207 | double d = extract_float (arg); | ||
| 208 | d = j1 (d); | ||
| 209 | return make_float (d); | ||
| 210 | } | ||
| 211 | |||
| 212 | DEFUN ("bessel-jn", Fbessel_jn, Sbessel_jn, 2, 2, 0, | ||
| 213 | doc: /* Return the order N bessel function output jn of ARG. | ||
| 214 | The first arg (the order) is truncated to an integer. */) | ||
| 215 | (Lisp_Object n, Lisp_Object arg) | ||
| 216 | { | ||
| 217 | int i1 = extract_float (n); | ||
| 218 | double f2 = extract_float (arg); | ||
| 219 | |||
| 220 | f2 = jn (i1, f2); | ||
| 221 | return make_float (f2); | ||
| 222 | } | ||
| 223 | |||
| 224 | DEFUN ("bessel-y0", Fbessel_y0, Sbessel_y0, 1, 1, 0, | ||
| 225 | doc: /* Return the bessel function y0 of ARG. */) | ||
| 226 | (Lisp_Object arg) | ||
| 227 | { | ||
| 228 | double d = extract_float (arg); | ||
| 229 | d = y0 (d); | ||
| 230 | return make_float (d); | ||
| 231 | } | ||
| 232 | |||
| 233 | DEFUN ("bessel-y1", Fbessel_y1, Sbessel_y1, 1, 1, 0, | ||
| 234 | doc: /* Return the bessel function y1 of ARG. */) | ||
| 235 | (Lisp_Object arg) | ||
| 236 | { | ||
| 237 | double d = extract_float (arg); | ||
| 238 | d = y1 (d); | ||
| 239 | return make_float (d); | ||
| 240 | } | ||
| 241 | |||
| 242 | DEFUN ("bessel-yn", Fbessel_yn, Sbessel_yn, 2, 2, 0, | ||
| 243 | doc: /* Return the order N bessel function output yn of ARG. | ||
| 244 | The first arg (the order) is truncated to an integer. */) | ||
| 245 | (Lisp_Object n, Lisp_Object arg) | ||
| 246 | { | ||
| 247 | int i1 = extract_float (n); | ||
| 248 | double f2 = extract_float (arg); | ||
| 249 | |||
| 250 | f2 = yn (i1, f2); | ||
| 251 | return make_float (f2); | ||
| 252 | } | ||
| 253 | |||
| 254 | #endif | ||
| 255 | |||
| 256 | #if 0 /* Leave these out unless we see they are worth having. */ | ||
| 257 | |||
| 258 | DEFUN ("erf", Ferf, Serf, 1, 1, 0, | ||
| 259 | doc: /* Return the mathematical error function of ARG. */) | ||
| 260 | (Lisp_Object arg) | ||
| 261 | { | ||
| 262 | double d = extract_float (arg); | ||
| 263 | d = erf (d); | ||
| 264 | return make_float (d); | ||
| 265 | } | ||
| 266 | |||
| 267 | DEFUN ("erfc", Ferfc, Serfc, 1, 1, 0, | ||
| 268 | doc: /* Return the complementary error function of ARG. */) | ||
| 269 | (Lisp_Object arg) | ||
| 270 | { | ||
| 271 | double d = extract_float (arg); | ||
| 272 | d = erfc (d); | ||
| 273 | return make_float (d); | ||
| 274 | } | ||
| 275 | |||
| 276 | DEFUN ("log-gamma", Flog_gamma, Slog_gamma, 1, 1, 0, | ||
| 277 | doc: /* Return the log gamma of ARG. */) | ||
| 278 | (Lisp_Object arg) | ||
| 279 | { | ||
| 280 | double d = extract_float (arg); | ||
| 281 | d = lgamma (d); | ||
| 282 | return make_float (d); | ||
| 283 | } | ||
| 284 | |||
| 285 | DEFUN ("cube-root", Fcube_root, Scube_root, 1, 1, 0, | ||
| 286 | doc: /* Return the cube root of ARG. */) | ||
| 287 | (Lisp_Object arg) | ||
| 288 | { | ||
| 289 | double d = extract_float (arg); | ||
| 290 | #ifdef HAVE_CBRT | ||
| 291 | d = cbrt (d); | ||
| 292 | #else | ||
| 293 | if (d >= 0.0) | ||
| 294 | d = pow (d, 1.0/3.0); | ||
| 295 | else | ||
| 296 | d = -pow (-d, 1.0/3.0); | ||
| 297 | #endif | ||
| 298 | return make_float (d); | ||
| 299 | } | ||
| 300 | |||
| 301 | #endif | ||
| 302 | 185 | ||
| 303 | DEFUN ("exp", Fexp, Sexp, 1, 1, 0, | 186 | DEFUN ("exp", Fexp, Sexp, 1, 1, 0, |
| 304 | doc: /* Return the exponential base e of ARG. */) | 187 | doc: /* Return the exponential base e of ARG. */) |
| @@ -383,63 +266,6 @@ DEFUN ("sqrt", Fsqrt, Ssqrt, 1, 1, 0, | |||
| 383 | return make_float (d); | 266 | return make_float (d); |
| 384 | } | 267 | } |
| 385 | 268 | ||
| 386 | #if 0 /* Not clearly worth adding. */ | ||
| 387 | |||
| 388 | DEFUN ("acosh", Facosh, Sacosh, 1, 1, 0, | ||
| 389 | doc: /* Return the inverse hyperbolic cosine of ARG. */) | ||
| 390 | (Lisp_Object arg) | ||
| 391 | { | ||
| 392 | double d = extract_float (arg); | ||
| 393 | d = acosh (d); | ||
| 394 | return make_float (d); | ||
| 395 | } | ||
| 396 | |||
| 397 | DEFUN ("asinh", Fasinh, Sasinh, 1, 1, 0, | ||
| 398 | doc: /* Return the inverse hyperbolic sine of ARG. */) | ||
| 399 | (Lisp_Object arg) | ||
| 400 | { | ||
| 401 | double d = extract_float (arg); | ||
| 402 | d = asinh (d); | ||
| 403 | return make_float (d); | ||
| 404 | } | ||
| 405 | |||
| 406 | DEFUN ("atanh", Fatanh, Satanh, 1, 1, 0, | ||
| 407 | doc: /* Return the inverse hyperbolic tangent of ARG. */) | ||
| 408 | (Lisp_Object arg) | ||
| 409 | { | ||
| 410 | double d = extract_float (arg); | ||
| 411 | d = atanh (d); | ||
| 412 | return make_float (d); | ||
| 413 | } | ||
| 414 | |||
| 415 | DEFUN ("cosh", Fcosh, Scosh, 1, 1, 0, | ||
| 416 | doc: /* Return the hyperbolic cosine of ARG. */) | ||
| 417 | (Lisp_Object arg) | ||
| 418 | { | ||
| 419 | double d = extract_float (arg); | ||
| 420 | d = cosh (d); | ||
| 421 | return make_float (d); | ||
| 422 | } | ||
| 423 | |||
| 424 | DEFUN ("sinh", Fsinh, Ssinh, 1, 1, 0, | ||
| 425 | doc: /* Return the hyperbolic sine of ARG. */) | ||
| 426 | (Lisp_Object arg) | ||
| 427 | { | ||
| 428 | double d = extract_float (arg); | ||
| 429 | d = sinh (d); | ||
| 430 | return make_float (d); | ||
| 431 | } | ||
| 432 | |||
| 433 | DEFUN ("tanh", Ftanh, Stanh, 1, 1, 0, | ||
| 434 | doc: /* Return the hyperbolic tangent of ARG. */) | ||
| 435 | (Lisp_Object arg) | ||
| 436 | { | ||
| 437 | double d = extract_float (arg); | ||
| 438 | d = tanh (d); | ||
| 439 | return make_float (d); | ||
| 440 | } | ||
| 441 | #endif | ||
| 442 | |||
| 443 | DEFUN ("abs", Fabs, Sabs, 1, 1, 0, | 269 | DEFUN ("abs", Fabs, Sabs, 1, 1, 0, |
| 444 | doc: /* Return the absolute value of ARG. */) | 270 | doc: /* Return the absolute value of ARG. */) |
| 445 | (register Lisp_Object arg) | 271 | (register Lisp_Object arg) |
| @@ -477,16 +303,15 @@ This is the same as the exponent of a float. */) | |||
| 477 | 303 | ||
| 478 | if (f == 0.0) | 304 | if (f == 0.0) |
| 479 | value = MOST_NEGATIVE_FIXNUM; | 305 | value = MOST_NEGATIVE_FIXNUM; |
| 480 | else | 306 | else if (isfinite (f)) |
| 481 | { | 307 | { |
| 482 | #ifdef HAVE_LOGB | ||
| 483 | value = logb (f); | ||
| 484 | #else | ||
| 485 | int ivalue; | 308 | int ivalue; |
| 486 | frexp (f, &ivalue); | 309 | frexp (f, &ivalue); |
| 487 | value = ivalue - 1; | 310 | value = ivalue - 1; |
| 488 | #endif | ||
| 489 | } | 311 | } |
| 312 | else | ||
| 313 | value = MOST_POSITIVE_FIXNUM; | ||
| 314 | |||
| 490 | XSETINT (val, value); | 315 | XSETINT (val, value); |
| 491 | return val; | 316 | return val; |
| 492 | } | 317 | } |
| @@ -719,27 +544,9 @@ syms_of_floatfns (void) | |||
| 719 | defsubr (&Sisnan); | 544 | defsubr (&Sisnan); |
| 720 | #ifdef HAVE_COPYSIGN | 545 | #ifdef HAVE_COPYSIGN |
| 721 | defsubr (&Scopysign); | 546 | defsubr (&Scopysign); |
| 547 | #endif | ||
| 722 | defsubr (&Sfrexp); | 548 | defsubr (&Sfrexp); |
| 723 | defsubr (&Sldexp); | 549 | defsubr (&Sldexp); |
| 724 | #endif | ||
| 725 | #if 0 | ||
| 726 | defsubr (&Sacosh); | ||
| 727 | defsubr (&Sasinh); | ||
| 728 | defsubr (&Satanh); | ||
| 729 | defsubr (&Scosh); | ||
| 730 | defsubr (&Ssinh); | ||
| 731 | defsubr (&Stanh); | ||
| 732 | defsubr (&Sbessel_y0); | ||
| 733 | defsubr (&Sbessel_y1); | ||
| 734 | defsubr (&Sbessel_yn); | ||
| 735 | defsubr (&Sbessel_j0); | ||
| 736 | defsubr (&Sbessel_j1); | ||
| 737 | defsubr (&Sbessel_jn); | ||
| 738 | defsubr (&Serf); | ||
| 739 | defsubr (&Serfc); | ||
| 740 | defsubr (&Slog_gamma); | ||
| 741 | defsubr (&Scube_root); | ||
| 742 | #endif | ||
| 743 | defsubr (&Sfceiling); | 550 | defsubr (&Sfceiling); |
| 744 | defsubr (&Sffloor); | 551 | defsubr (&Sffloor); |
| 745 | defsubr (&Sfround); | 552 | defsubr (&Sfround); |
diff --git a/src/lisp.h b/src/lisp.h index 240e8c08a87..ae9b3422534 100644 --- a/src/lisp.h +++ b/src/lisp.h | |||
| @@ -2559,8 +2559,7 @@ extern Lisp_Object Qchar_table_p, Qvector_or_char_table_p; | |||
| 2559 | 2559 | ||
| 2560 | extern Lisp_Object Qcdr; | 2560 | extern Lisp_Object Qcdr; |
| 2561 | 2561 | ||
| 2562 | extern Lisp_Object Qrange_error, Qdomain_error, Qsingularity_error; | 2562 | extern Lisp_Object Qrange_error, Qoverflow_error; |
| 2563 | extern Lisp_Object Qoverflow_error, Qunderflow_error; | ||
| 2564 | 2563 | ||
| 2565 | extern Lisp_Object Qfloatp; | 2564 | extern Lisp_Object Qfloatp; |
| 2566 | extern Lisp_Object Qnumberp, Qnumber_or_marker_p; | 2565 | extern Lisp_Object Qnumberp, Qnumber_or_marker_p; |