Mercurial > emacs
comparison src/floatfns.c @ 1005:70ed307d9047
* floatfns.c (Fexpm1, Flog1p): Function removed; it's not widely
available, and hardly vital.
(syms_of_floatfns): Adjusted appropriately.
* floatfns.c (Flog): Accept optional second arg, being the base
for the logarithm.
[USG] (Flogb): Define this in terms of Flog.
author | Jim Blandy <jimb@redhat.com> |
---|---|
date | Wed, 19 Aug 1992 06:26:13 +0000 |
parents | 714b8017cc6b |
children | bef6b6903528 |
comparison
equal
deleted
inserted
replaced
1004:5318f9b7e442 | 1005:70ed307d9047 |
---|---|
259 (num) | 259 (num) |
260 register Lisp_Object num; | 260 register Lisp_Object num; |
261 { | 261 { |
262 double d = extract_float (num); | 262 double d = extract_float (num); |
263 IN_FLOAT (d = exp (d), num); | 263 IN_FLOAT (d = exp (d), num); |
264 return make_float (d); | |
265 } | |
266 | |
267 DEFUN ("expm1", Fexpm1, Sexpm1, 1, 1, 0, | |
268 "Return the exp (x)-1 of ARG.") | |
269 (num) | |
270 register Lisp_Object num; | |
271 { | |
272 double d = extract_float (num); | |
273 IN_FLOAT (d = expm1 (d), num); | |
274 return make_float (d); | 264 return make_float (d); |
275 } | 265 } |
276 | 266 |
277 DEFUN ("expt", Fexpt, Sexpt, 2, 2, 0, | 267 DEFUN ("expt", Fexpt, Sexpt, 2, 2, 0, |
278 "Return the exponential X ** Y.") | 268 "Return the exponential X ** Y.") |
308 f2 = (XTYPE (num2) == Lisp_Float) ? XFLOAT (num2)->data : XINT (num2); | 298 f2 = (XTYPE (num2) == Lisp_Float) ? XFLOAT (num2)->data : XINT (num2); |
309 IN_FLOAT (f1 = pow (f1, f2), num1); | 299 IN_FLOAT (f1 = pow (f1, f2), num1); |
310 return make_float (f1); | 300 return make_float (f1); |
311 } | 301 } |
312 | 302 |
313 DEFUN ("log", Flog, Slog, 1, 1, 0, | 303 DEFUN ("log", Flog, Slog, 1, 2, 0, |
314 "Return the natural logarithm of ARG.") | 304 "Return the natural logarithm of NUM. |
315 (num) | 305 If second optional argument BASE is given, return log NUM using that base.") |
316 register Lisp_Object num; | 306 (num, base) |
317 { | 307 register Lisp_Object num; |
318 double d = extract_float (num); | 308 { |
319 IN_FLOAT (d = log (d), num); | 309 double d = extract_float (num); |
310 | |
311 if (NILP (base)) | |
312 IN_FLOAT (d = log (d), num); | |
313 else | |
314 { | |
315 double b = extract_float (base); | |
316 | |
317 IN_FLOAT (d = log (num) / log (b), num); | |
318 } | |
320 return make_float (d); | 319 return make_float (d); |
321 } | 320 } |
322 | 321 |
323 DEFUN ("log10", Flog10, Slog10, 1, 1, 0, | 322 DEFUN ("log10", Flog10, Slog10, 1, 1, 0, |
324 "Return the logarithm base 10 of ARG.") | 323 "Return the logarithm base 10 of ARG.") |
325 (num) | 324 (num) |
326 register Lisp_Object num; | 325 register Lisp_Object num; |
327 { | 326 { |
328 double d = extract_float (num); | 327 double d = extract_float (num); |
329 IN_FLOAT (d = log10 (d), num); | 328 IN_FLOAT (d = log10 (d), num); |
330 return make_float (d); | |
331 } | |
332 | |
333 DEFUN ("log1p", Flog1p, Slog1p, 1, 1, 0, | |
334 "Return the log (1+x) of ARG.") | |
335 (num) | |
336 register Lisp_Object num; | |
337 { | |
338 double d = extract_float (num); | |
339 IN_FLOAT (d = log1p (d), num); | |
340 return make_float (d); | 329 return make_float (d); |
341 } | 330 } |
342 | 331 |
343 DEFUN ("sqrt", Fsqrt, Ssqrt, 1, 1, 0, | 332 DEFUN ("sqrt", Fsqrt, Ssqrt, 1, 1, 0, |
344 "Return the square root of ARG.") | 333 "Return the square root of ARG.") |
445 "Returns the integer that is the base 2 log of ARG.\n\ | 434 "Returns the integer that is the base 2 log of ARG.\n\ |
446 This is the same as the exponent of a float.") | 435 This is the same as the exponent of a float.") |
447 (num) | 436 (num) |
448 Lisp_Object num; | 437 Lisp_Object num; |
449 { | 438 { |
439 #ifdef USG | |
440 /* System V apparently doesn't have a `logb' function. */ | |
441 return Flog (num, make_number (2)); | |
442 #else | |
450 Lisp_Object val; | 443 Lisp_Object val; |
451 double f; | 444 double f = extract_float (num); |
452 | 445 |
453 CHECK_NUMBER_OR_FLOAT (num, 0); | |
454 f = (XTYPE (num) == Lisp_Float) ? XFLOAT (num)->data : XINT (num); | |
455 IN_FLOAT (val = logb (f), num); | 446 IN_FLOAT (val = logb (f), num); |
456 XSET (val, Lisp_Int, val); | 447 XSET (val, Lisp_Int, val); |
457 return val; | 448 return val; |
449 #endif | |
458 } | 450 } |
459 | 451 |
460 /* the rounding functions */ | 452 /* the rounding functions */ |
461 | 453 |
462 DEFUN ("ceiling", Fceiling, Sceiling, 1, 1, 0, | 454 DEFUN ("ceiling", Fceiling, Sceiling, 1, 1, 0, |
491 register Lisp_Object num; | 483 register Lisp_Object num; |
492 { | 484 { |
493 CHECK_NUMBER_OR_FLOAT (num, 0); | 485 CHECK_NUMBER_OR_FLOAT (num, 0); |
494 | 486 |
495 if (XTYPE (num) == Lisp_Float) | 487 if (XTYPE (num) == Lisp_Float) |
496 IN_FLOAT (XSET (num, Lisp_Int, rint (XFLOAT (num)->data)), num); | 488 { |
489 #ifdef USG | |
490 /* Screw the prevailing rounding mode. */ | |
491 IN_FLOAT (XSET (num, Lisp_Int, floor (XFLOAT (num)->data + 0.5)), num); | |
492 #else | |
493 IN_FLOAT (XSET (num, Lisp_Int, rint (XFLOAT (num)->data)), num); | |
494 #endif | |
495 } | |
497 | 496 |
498 return num; | 497 return num; |
499 } | 498 } |
500 | 499 |
501 DEFUN ("truncate", Ftruncate, Struncate, 1, 1, 0, | 500 DEFUN ("truncate", Ftruncate, Struncate, 1, 1, 0, |
566 defsubr (&Serfc); | 565 defsubr (&Serfc); |
567 defsubr (&Slog_gamma); | 566 defsubr (&Slog_gamma); |
568 defsubr (&Scbrt); | 567 defsubr (&Scbrt); |
569 #endif | 568 #endif |
570 defsubr (&Sexp); | 569 defsubr (&Sexp); |
571 defsubr (&Sexpm1); | |
572 defsubr (&Sexpt); | 570 defsubr (&Sexpt); |
573 defsubr (&Slog); | 571 defsubr (&Slog); |
574 defsubr (&Slog10); | 572 defsubr (&Slog10); |
575 defsubr (&Slog1p); | |
576 defsubr (&Ssqrt); | 573 defsubr (&Ssqrt); |
577 | 574 |
578 defsubr (&Sabs); | 575 defsubr (&Sabs); |
579 defsubr (&Sfloat); | 576 defsubr (&Sfloat); |
580 defsubr (&Slogb); | 577 defsubr (&Slogb); |