#include "lisp.h"
+#include <math.h>
#include <stdlib.h>
/* mpz global temporaries. Making them global saves the trouble of
return mpz_get_d (XBIGNUM (n)->value);
}
-/* Return D, converted to a Lisp integer. Discard any fraction. */
+/* Return D, converted to a Lisp integer. Discard any fraction.
+ Signal an error if D cannot be converted. */
Lisp_Object
double_to_integer (double d)
{
+ if (!isfinite (d))
+ overflow_error ();
mpz_set_d (mpz[0], d);
return make_integer_mpz ();
}
(or (/= cdelta fdelta)
(zerop (% (round n d) 2)))))))))))
+(ert-deftest special-round ()
+ (let ((ns '(-1e+INF 1e+INF -1 1 -1e+NaN 1e+NaN)))
+ (dolist (n ns)
+ (unless (<= (abs n) 1)
+ (should-error (ceiling n))
+ (should-error (floor n))
+ (should-error (round n))
+ (should-error (truncate n)))
+ (dolist (d ns)
+ (unless (<= (abs (/ n d)) 1)
+ (should-error (ceiling n d))
+ (should-error (floor n d))
+ (should-error (round n d))
+ (should-error (truncate n d)))))))
+
(provide 'floatfns-tests)