Mercurial > emacs
comparison src/floatfns.c @ 108307:767894eefe6c
* floatfns.c (Fisnan, Fcopysign, Ffrexp, Fldexp): New functions.
* configure.in: Add tests for `isnan' and `copysign'.
| author | Stefan Monnier <monnier@iro.umontreal.ca> |
|---|---|
| date | Fri, 07 May 2010 14:55:18 -0400 |
| parents | 912a8c0c9a8a |
| children | c25c24812fb1 |
comparison
equal
deleted
inserted
replaced
| 108306:8ceadb47c51e | 108307:767894eefe6c |
|---|---|
| 286 domain_error ("tan", arg); | 286 domain_error ("tan", arg); |
| 287 #endif | 287 #endif |
| 288 IN_FLOAT (d = sin (d) / c, "tan", arg); | 288 IN_FLOAT (d = sin (d) / c, "tan", arg); |
| 289 return make_float (d); | 289 return make_float (d); |
| 290 } | 290 } |
| 291 | |
| 292 #if defined HAVE_ISNAN && defined HAVE_COPYSIGN | |
| 293 DEFUN ("isnan", Fisnan, Sisnan, 1, 1, 0, | |
| 294 doc: /* Return non nil iff argument X is a NaN. */) | |
| 295 (x) | |
| 296 Lisp_Object x; | |
| 297 { | |
| 298 CHECK_FLOAT (x); | |
| 299 return isnan (XFLOAT_DATA (x)) ? Qt : Qnil; | |
| 300 } | |
| 301 | |
| 302 DEFUN ("copysign", Fcopysign, Scopysign, 1, 2, 0, | |
| 303 doc: /* Copy sign of X2 to value of X1, and return the result. | |
| 304 Cause an error if X1 or X2 is not a float. */) | |
| 305 (x1, x2) | |
| 306 Lisp_Object x1, x2; | |
| 307 { | |
| 308 double f1, f2; | |
| 309 | |
| 310 CHECK_FLOAT (x1); | |
| 311 CHECK_FLOAT (x2); | |
| 312 | |
| 313 f1 = XFLOAT_DATA (x1); | |
| 314 f2 = XFLOAT_DATA (x2); | |
| 315 | |
| 316 return make_float (copysign (f1, f2)); | |
| 317 } | |
| 318 | |
| 319 DEFUN ("frexp", Ffrexp, Sfrexp, 1, 1, 0, | |
| 320 doc: /* Get significand and exponent of a floating point number. | |
| 321 Breaks the floating point number X into its binary significand SGNFCAND | |
| 322 \(a floating point value between 0.5 (included) and 1.0 (excluded)) | |
| 323 and an integral exponent EXP for 2, such that: | |
| 324 | |
| 325 X = SGNFCAND * 2^EXP | |
| 326 | |
| 327 The function returns the cons cell (SGNFCAND . EXP). | |
| 328 If X is zero, both parts (SGNFCAND and EXP) are zero. */) | |
| 329 (x) | |
| 330 Lisp_Object x; | |
| 331 { | |
| 332 double f = XFLOATINT (x); | |
| 333 | |
| 334 if (f == 0.0) | |
| 335 return Fcons (make_float (0.0), make_number (0)); | |
| 336 else | |
| 337 { | |
| 338 int exp; | |
| 339 double sgnfcand = frexp (f, &exp); | |
| 340 return Fcons (make_float (sgnfcand), make_number (exp)); | |
| 341 } | |
| 342 } | |
| 343 | |
| 344 DEFUN ("ldexp", Fldexp, Sldexp, 1, 2, 0, | |
| 345 doc: /* Construct number X from significand SGNFCAND and exponent EXP. | |
| 346 Returns the floating point value resulting from multiplying SGNFCAND | |
| 347 (the significand) by 2 raised to the power of EXP (the exponent). */) | |
| 348 (sgnfcand, exp) | |
| 349 Lisp_Object sgnfcand, exp; | |
| 350 { | |
| 351 CHECK_NUMBER (exp); | |
| 352 return make_float (ldexp (XFLOATINT (sgnfcand), XINT (exp))); | |
| 353 } | |
| 354 #endif | |
| 291 | 355 |
| 292 #if 0 /* Leave these out unless we find there's a reason for them. */ | 356 #if 0 /* Leave these out unless we find there's a reason for them. */ |
| 293 | 357 |
| 294 DEFUN ("bessel-j0", Fbessel_j0, Sbessel_j0, 1, 1, 0, | 358 DEFUN ("bessel-j0", Fbessel_j0, Sbessel_j0, 1, 1, 0, |
| 295 doc: /* Return the bessel function j0 of ARG. */) | 359 doc: /* Return the bessel function j0 of ARG. */) |
| 1015 defsubr (&Sasin); | 1079 defsubr (&Sasin); |
| 1016 defsubr (&Satan); | 1080 defsubr (&Satan); |
| 1017 defsubr (&Scos); | 1081 defsubr (&Scos); |
| 1018 defsubr (&Ssin); | 1082 defsubr (&Ssin); |
| 1019 defsubr (&Stan); | 1083 defsubr (&Stan); |
| 1084 #if defined HAVE_ISNAN && defined HAVE_COPYSIGN | |
| 1085 defsubr (&Sisnan); | |
| 1086 defsubr (&Scopysign); | |
| 1087 defsubr (&Sfrexp); | |
| 1088 defsubr (&Sldexp); | |
| 1089 #endif | |
| 1020 #if 0 | 1090 #if 0 |
| 1021 defsubr (&Sacosh); | 1091 defsubr (&Sacosh); |
| 1022 defsubr (&Sasinh); | 1092 defsubr (&Sasinh); |
| 1023 defsubr (&Satanh); | 1093 defsubr (&Satanh); |
| 1024 defsubr (&Scosh); | 1094 defsubr (&Scosh); |
