#include <signal.h>
-#include "config.h"
+#include <config.h>
#include "lisp.h"
#include "syssignal.h"
#ifdef LISP_FLOAT_TYPE
+/* Work around a problem that happens because math.h on hpux 7
+ defines two static variables--which, in Emacs, are not really static,
+ because `static' is defined as nothing. The problem is that they are
+ defined both here and in lread.c.
+ These macros prevent the name conflict. */
+#if defined (HPUX) && !defined (HPUX8)
+#define _MAXLDBL floatfns_maxldbl
+#define _NMAXLDBL floatfns_nmaxldbl
+#endif
+
#include <math.h>
-#ifndef hpux
-/* These declarations are omitted on some systems, like Ultrix. */
+/* This declaration is omitted on some systems, like Ultrix. */
+#if !defined (hpux) && defined (HAVE_LOGB)
extern double logb ();
-#endif
+#endif /* !hpux && HAVE_LOGB */
#if defined(DOMAIN) && defined(SING) && defined(OVERFLOW)
/* If those are defined, then this is probably a `matherr' machine. */
CHECK_NUMBER_OR_FLOAT (arg1, 0);
CHECK_NUMBER_OR_FLOAT (arg2, 0);
- if ((XTYPE (arg1) == Lisp_Int) && /* common lisp spec */
- (XTYPE (arg2) == Lisp_Int)) /* don't promote, if both are ints */
+ if (XTYPE (arg1) == Lisp_Int /* common lisp spec */
+ && XTYPE (arg2) == Lisp_Int) /* don't promote, if both are ints */
{ /* this can be improved by pre-calculating */
- int acc, x, y; /* some binary powers of x then acumulating */
- /* these, therby saving some time. -wsr */
+ int acc, x, y; /* some binary powers of x then accumulating */
+ Lisp_Object val;
+
x = XINT (arg1);
y = XINT (arg2);
acc = 1;
y = (unsigned)y >> 1;
}
}
- XSET (x, Lisp_Int, acc);
- return x;
+ XSET (val, Lisp_Int, acc);
+ return val;
}
f1 = (XTYPE (arg1) == Lisp_Float) ? XFLOAT (arg1)->data : XINT (arg1);
f2 = (XTYPE (arg2) == Lisp_Float) ? XFLOAT (arg2)->data : XINT (arg2);
else if ((f1 == 0.0 && f2 < 0.0) || (f1 < 0 && f2 != floor(f2)))
domain_error2 ("expt", arg1, arg2);
#endif
- IN_FLOAT (f1 = pow (f1, f2), "expt", arg1);
+ IN_FLOAT2 (f1 = pow (f1, f2), "expt", arg1, arg2);
return make_float (f1);
}
}
DEFUN ("logb", Flogb, Slogb, 1, 1, 0,
- "Returns the integer not greater than the base 2 log of the magnitude of ARG.\n\
+ "Returns largest integer <= the base 2 log of the magnitude of ARG.\n\
This is the same as the exponent of a float.")
(arg)
Lisp_Object arg;
int value;
double f = extract_float (arg);
-#ifdef USG
+#ifdef HAVE_LOGB
+ IN_FLOAT (value = logb (f), "logb", arg);
+ XSET (val, Lisp_Int, value);
+#else
+#ifdef HAVE_FREXP
{
int exp;
XSET (val, Lisp_Int, exp-1);
}
#else
- IN_FLOAT (value = logb (f), "logb", arg);
- XSET (val, Lisp_Int, value);
+ /* Would someone like to write code to emulate logb? */
+ error ("`logb' not implemented on this operating system");
+#endif
#endif
return val;
return arg;
}
-DEFUN ("floor", Ffloor, Sfloor, 1, 1, 0,
- "Return the largest integer no greater than ARG. (Round towards -inf.)")
- (arg)
- register Lisp_Object arg;
+#endif /* LISP_FLOAT_TYPE */
+
+
+DEFUN ("floor", Ffloor, Sfloor, 1, 2, 0,
+ "Return the largest integer no greater than ARG. (Round towards -inf.)\n\
+With optional DIVISOR, return the largest integer no greater than ARG/DIVISOR.")
+ (arg, divisor)
+ register Lisp_Object arg, divisor;
{
CHECK_NUMBER_OR_FLOAT (arg, 0);
+ if (! NILP (divisor))
+ {
+ int i1, i2;
+
+ CHECK_NUMBER_OR_FLOAT (divisor, 1);
+
+#ifdef LISP_FLOAT_TYPE
+ if (XTYPE (arg) == Lisp_Float || XTYPE (divisor) == Lisp_Float)
+ {
+ double f1, f2;
+
+ f1 = XTYPE (arg) == Lisp_Float ? XFLOAT (arg)->data : XINT (arg);
+ f2 = (XTYPE (divisor) == Lisp_Float
+ ? XFLOAT (divisor)->data : XINT (divisor));
+ if (f2 == 0)
+ Fsignal (Qarith_error, Qnil);
+
+ IN_FLOAT2 (XSET (arg, Lisp_Int, floor (f1 / f2)),
+ "floor", arg, divisor);
+ return arg;
+ }
+#endif
+
+ i1 = XINT (arg);
+ i2 = XINT (divisor);
+
+ if (i2 == 0)
+ Fsignal (Qarith_error, Qnil);
+
+ /* With C's /, the result is implementation-defined if either operand
+ is negative, so use only nonnegative operands. */
+ i1 = (i2 < 0
+ ? (i1 <= 0 ? -i1 / -i2 : -1 - ((i1 - 1) / -i2))
+ : (i1 < 0 ? -1 - ((-1 - i1) / i2) : i1 / i2));
+
+ XSET (arg, Lisp_Int, i1);
+ return arg;
+ }
+
+#ifdef LISP_FLOAT_TYPE
if (XTYPE (arg) == Lisp_Float)
IN_FLOAT (XSET (arg, Lisp_Int, floor (XFLOAT (arg)->data)), "floor", arg);
+#endif
return arg;
}
+#ifdef LISP_FLOAT_TYPE
+
DEFUN ("round", Fround, Sround, 1, 1, 0,
"Return the nearest integer to ARG.")
(arg)
in_float = 0;
}
+#else /* not LISP_FLOAT_TYPE */
+
+init_floatfns ()
+{}
+
+#endif /* not LISP_FLOAT_TYPE */
+
syms_of_floatfns ()
{
+#ifdef LISP_FLOAT_TYPE
defsubr (&Sacos);
defsubr (&Sasin);
defsubr (&Satan);
defsubr (&Sfloat);
defsubr (&Slogb);
defsubr (&Sceiling);
- defsubr (&Sfloor);
defsubr (&Sround);
defsubr (&Struncate);
+#endif /* LISP_FLOAT_TYPE */
+ defsubr (&Sfloor);
}
-
-#else /* not LISP_FLOAT_TYPE */
-
-init_floatfns ()
-{}
-
-syms_of_floatfns ()
-{}
-
-#endif /* not LISP_FLOAT_TYPE */