aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert2015-03-24 11:42:53 -0700
committerPaul Eggert2015-03-24 11:43:21 -0700
commit711770da9101a94ada42881cb86a976d323e9348 (patch)
tree71465e72be54b14ec973cbf50a4a424449b31a07 /src
parent1e043f5e79bf67c9ebfa35623edcff0633d37a75 (diff)
downloademacs-711770da9101a94ada42881cb86a976d323e9348.tar.gz
emacs-711770da9101a94ada42881cb86a976d323e9348.zip
Fix minor ldexp issues
* doc/lispref/numbers.texi (Float Basics): Improve ldexp documentation. * src/floatfns.c (Fldexp): Require 2 args. Avoid undefined behavior if the exponent is out of 'int' range. Improve documentation. Fixes: bug#20185
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog7
-rw-r--r--src/floatfns.c10
2 files changed, 12 insertions, 5 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 815c117308b..23f125c567d 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,10 @@
12015-03-24 Paul Eggert <eggert@cs.ucla.edu>
2
3 Fix minor ldexp issues
4 * floatfns.c (Fldexp): Require 2 args. Avoid undefined behavior
5 if the exponent is out of 'int' range. Improve documentation.
6 Fixes: bug#20185
7
12015-03-24 Daniel Colascione <dancol@dancol.org> 82015-03-24 Daniel Colascione <dancol@dancol.org>
2 9
3 * process.c (Fprocess_running_child_p): Return number identifier of 10 * process.c (Fprocess_running_child_p): Return number identifier of
diff --git a/src/floatfns.c b/src/floatfns.c
index c68b9bd3a65..072e85776b5 100644
--- a/src/floatfns.c
+++ b/src/floatfns.c
@@ -185,14 +185,14 @@ If X is zero, both parts (SGNFCAND and EXP) are zero. */)
185 return Fcons (make_float (sgnfcand), make_number (exponent)); 185 return Fcons (make_float (sgnfcand), make_number (exponent));
186} 186}
187 187
188DEFUN ("ldexp", Fldexp, Sldexp, 1, 2, 0, 188DEFUN ("ldexp", Fldexp, Sldexp, 2, 2, 0,
189 doc: /* Construct number X from significand SGNFCAND and exponent EXP. 189 doc: /* Return X * 2**EXP, as a floating point number.
190Returns the floating point value resulting from multiplying SGNFCAND 190EXP must be an integer. */)
191(the significand) by 2 raised to the power of EXP (the exponent). */)
192 (Lisp_Object sgnfcand, Lisp_Object exponent) 191 (Lisp_Object sgnfcand, Lisp_Object exponent)
193{ 192{
194 CHECK_NUMBER (exponent); 193 CHECK_NUMBER (exponent);
195 return make_float (ldexp (XFLOATINT (sgnfcand), XINT (exponent))); 194 int e = min (max (INT_MIN, XINT (exponent)), INT_MAX);
195 return make_float (ldexp (XFLOATINT (sgnfcand), e));
196} 196}
197 197
198DEFUN ("exp", Fexp, Sexp, 1, 1, 0, 198DEFUN ("exp", Fexp, Sexp, 1, 1, 0,