Mercurial > hg > xemacs-beta
comparison src/floatfns.c @ 20:859a2309aef8 r19-15b93
Import from CVS: tag r19-15b93
author | cvs |
---|---|
date | Mon, 13 Aug 2007 08:50:05 +0200 |
parents | 376386a54a3c |
children | 4be1180a9e89 |
comparison
equal
deleted
inserted
replaced
19:ac1f612d5250 | 20:859a2309aef8 |
---|---|
204 | 204 |
205 | 205 |
206 /* Trig functions. */ | 206 /* Trig functions. */ |
207 #ifdef LISP_FLOAT_TYPE | 207 #ifdef LISP_FLOAT_TYPE |
208 | 208 |
209 DEFUN ("acos", Facos, Sacos, 1, 1, 0 /* | 209 DEFUN ("acos", Facos, 1, 1, 0, /* |
210 Return the inverse cosine of ARG. | 210 Return the inverse cosine of ARG. |
211 */ ) | 211 */ |
212 (arg) | 212 (arg)) |
213 Lisp_Object arg; | |
214 { | 213 { |
215 double d = extract_float (arg); | 214 double d = extract_float (arg); |
216 #ifdef FLOAT_CHECK_DOMAIN | 215 #ifdef FLOAT_CHECK_DOMAIN |
217 if (d > 1.0 || d < -1.0) | 216 if (d > 1.0 || d < -1.0) |
218 domain_error ("acos", arg); | 217 domain_error ("acos", arg); |
219 #endif | 218 #endif |
220 IN_FLOAT (d = acos (d), "acos", arg); | 219 IN_FLOAT (d = acos (d), "acos", arg); |
221 return make_float (d); | 220 return make_float (d); |
222 } | 221 } |
223 | 222 |
224 DEFUN ("asin", Fasin, Sasin, 1, 1, 0 /* | 223 DEFUN ("asin", Fasin, 1, 1, 0, /* |
225 Return the inverse sine of ARG. | 224 Return the inverse sine of ARG. |
226 */ ) | 225 */ |
227 (arg) | 226 (arg)) |
228 Lisp_Object arg; | |
229 { | 227 { |
230 double d = extract_float (arg); | 228 double d = extract_float (arg); |
231 #ifdef FLOAT_CHECK_DOMAIN | 229 #ifdef FLOAT_CHECK_DOMAIN |
232 if (d > 1.0 || d < -1.0) | 230 if (d > 1.0 || d < -1.0) |
233 domain_error ("asin", arg); | 231 domain_error ("asin", arg); |
234 #endif | 232 #endif |
235 IN_FLOAT (d = asin (d), "asin", arg); | 233 IN_FLOAT (d = asin (d), "asin", arg); |
236 return make_float (d); | 234 return make_float (d); |
237 } | 235 } |
238 | 236 |
239 DEFUN ("atan", Fatan, Satan, 1, 2, 0 /* | 237 DEFUN ("atan", Fatan, 1, 2, 0, /* |
240 Return the inverse tangent of ARG. | 238 Return the inverse tangent of ARG. |
241 */ ) | 239 */ |
242 (arg1, arg2) | 240 (arg1, arg2)) |
243 Lisp_Object arg1, arg2; | |
244 { | 241 { |
245 double d = extract_float (arg1); | 242 double d = extract_float (arg1); |
246 | 243 |
247 if (NILP (arg2)) | 244 if (NILP (arg2)) |
248 IN_FLOAT (d = atan (d), "atan", arg1); | 245 IN_FLOAT (d = atan (d), "atan", arg1); |
256 IN_FLOAT2 (d = atan2 (d, d2), "atan", arg1, arg2); | 253 IN_FLOAT2 (d = atan2 (d, d2), "atan", arg1, arg2); |
257 } | 254 } |
258 return make_float (d); | 255 return make_float (d); |
259 } | 256 } |
260 | 257 |
261 DEFUN ("cos", Fcos, Scos, 1, 1, 0 /* | 258 DEFUN ("cos", Fcos, 1, 1, 0, /* |
262 Return the cosine of ARG. | 259 Return the cosine of ARG. |
263 */ ) | 260 */ |
264 (arg) | 261 (arg)) |
265 Lisp_Object arg; | |
266 { | 262 { |
267 double d = extract_float (arg); | 263 double d = extract_float (arg); |
268 IN_FLOAT (d = cos (d), "cos", arg); | 264 IN_FLOAT (d = cos (d), "cos", arg); |
269 return make_float (d); | 265 return make_float (d); |
270 } | 266 } |
271 | 267 |
272 DEFUN ("sin", Fsin, Ssin, 1, 1, 0 /* | 268 DEFUN ("sin", Fsin, 1, 1, 0, /* |
273 Return the sine of ARG. | 269 Return the sine of ARG. |
274 */ ) | 270 */ |
275 (arg) | 271 (arg)) |
276 Lisp_Object arg; | |
277 { | 272 { |
278 double d = extract_float (arg); | 273 double d = extract_float (arg); |
279 IN_FLOAT (d = sin (d), "sin", arg); | 274 IN_FLOAT (d = sin (d), "sin", arg); |
280 return make_float (d); | 275 return make_float (d); |
281 } | 276 } |
282 | 277 |
283 DEFUN ("tan", Ftan, Stan, 1, 1, 0 /* | 278 DEFUN ("tan", Ftan, 1, 1, 0, /* |
284 Return the tangent of ARG. | 279 Return the tangent of ARG. |
285 */ ) | 280 */ |
286 (arg) | 281 (arg)) |
287 Lisp_Object arg; | |
288 { | 282 { |
289 double d = extract_float (arg); | 283 double d = extract_float (arg); |
290 double c = cos (d); | 284 double c = cos (d); |
291 #ifdef FLOAT_CHECK_DOMAIN | 285 #ifdef FLOAT_CHECK_DOMAIN |
292 if (c == 0.0) | 286 if (c == 0.0) |
300 | 294 |
301 /* Bessel functions */ | 295 /* Bessel functions */ |
302 #if 0 /* Leave these out unless we find there's a reason for them. */ | 296 #if 0 /* Leave these out unless we find there's a reason for them. */ |
303 /* #ifdef LISP_FLOAT_TYPE */ | 297 /* #ifdef LISP_FLOAT_TYPE */ |
304 | 298 |
305 DEFUN ("bessel-j0", Fbessel_j0, Sbessel_j0, 1, 1, 0 /* | 299 DEFUN ("bessel-j0", Fbessel_j0, 1, 1, 0, /* |
306 Return the bessel function j0 of ARG. | 300 Return the bessel function j0 of ARG. |
307 */ ) | 301 */ |
308 (arg) | 302 (arg)) |
309 Lisp_Object arg; | |
310 { | 303 { |
311 double d = extract_float (arg); | 304 double d = extract_float (arg); |
312 IN_FLOAT (d = j0 (d), "bessel-j0", arg); | 305 IN_FLOAT (d = j0 (d), "bessel-j0", arg); |
313 return make_float (d); | 306 return make_float (d); |
314 } | 307 } |
315 | 308 |
316 DEFUN ("bessel-j1", Fbessel_j1, Sbessel_j1, 1, 1, 0 /* | 309 DEFUN ("bessel-j1", Fbessel_j1, 1, 1, 0, /* |
317 Return the bessel function j1 of ARG. | 310 Return the bessel function j1 of ARG. |
318 */ ) | 311 */ |
319 (arg) | 312 (arg)) |
320 Lisp_Object arg; | |
321 { | 313 { |
322 double d = extract_float (arg); | 314 double d = extract_float (arg); |
323 IN_FLOAT (d = j1 (d), "bessel-j1", arg); | 315 IN_FLOAT (d = j1 (d), "bessel-j1", arg); |
324 return make_float (d); | 316 return make_float (d); |
325 } | 317 } |
326 | 318 |
327 DEFUN ("bessel-jn", Fbessel_jn, Sbessel_jn, 2, 2, 0 /* | 319 DEFUN ("bessel-jn", Fbessel_jn, 2, 2, 0, /* |
328 Return the order N bessel function output jn of ARG. | 320 Return the order N bessel function output jn of ARG. |
329 The first arg (the order) is truncated to an integer. | 321 The first arg (the order) is truncated to an integer. |
330 */ ) | 322 */ |
331 (arg1, arg2) | 323 (arg1, arg2)) |
332 Lisp_Object arg1, arg2; | |
333 { | 324 { |
334 int i1 = extract_float (arg1); | 325 int i1 = extract_float (arg1); |
335 double f2 = extract_float (arg2); | 326 double f2 = extract_float (arg2); |
336 | 327 |
337 IN_FLOAT (f2 = jn (i1, f2), "bessel-jn", arg1); | 328 IN_FLOAT (f2 = jn (i1, f2), "bessel-jn", arg1); |
338 return make_float (f2); | 329 return make_float (f2); |
339 } | 330 } |
340 | 331 |
341 DEFUN ("bessel-y0", Fbessel_y0, Sbessel_y0, 1, 1, 0 /* | 332 DEFUN ("bessel-y0", Fbessel_y0, 1, 1, 0, /* |
342 Return the bessel function y0 of ARG. | 333 Return the bessel function y0 of ARG. |
343 */ ) | 334 */ |
344 (arg) | 335 (arg)) |
345 Lisp_Object arg; | |
346 { | 336 { |
347 double d = extract_float (arg); | 337 double d = extract_float (arg); |
348 IN_FLOAT (d = y0 (d), "bessel-y0", arg); | 338 IN_FLOAT (d = y0 (d), "bessel-y0", arg); |
349 return make_float (d); | 339 return make_float (d); |
350 } | 340 } |
351 | 341 |
352 DEFUN ("bessel-y1", Fbessel_y1, Sbessel_y1, 1, 1, 0 /* | 342 DEFUN ("bessel-y1", Fbessel_y1, 1, 1, 0, /* |
353 Return the bessel function y1 of ARG. | 343 Return the bessel function y1 of ARG. |
354 */ ) | 344 */ |
355 (arg) | 345 (arg)) |
356 Lisp_Object arg; | |
357 { | 346 { |
358 double d = extract_float (arg); | 347 double d = extract_float (arg); |
359 IN_FLOAT (d = y1 (d), "bessel-y0", arg); | 348 IN_FLOAT (d = y1 (d), "bessel-y0", arg); |
360 return make_float (d); | 349 return make_float (d); |
361 } | 350 } |
362 | 351 |
363 DEFUN ("bessel-yn", Fbessel_yn, Sbessel_yn, 2, 2, 0 /* | 352 DEFUN ("bessel-yn", Fbessel_yn, 2, 2, 0, /* |
364 Return the order N bessel function output yn of ARG. | 353 Return the order N bessel function output yn of ARG. |
365 The first arg (the order) is truncated to an integer. | 354 The first arg (the order) is truncated to an integer. |
366 */ ) | 355 */ |
367 (arg1, arg2) | 356 (arg1, arg2)) |
368 Lisp_Object arg1, arg2; | |
369 { | 357 { |
370 int i1 = extract_float (arg1); | 358 int i1 = extract_float (arg1); |
371 double f2 = extract_float (arg2); | 359 double f2 = extract_float (arg2); |
372 | 360 |
373 IN_FLOAT (f2 = yn (i1, f2), "bessel-yn", arg1); | 361 IN_FLOAT (f2 = yn (i1, f2), "bessel-yn", arg1); |
378 | 366 |
379 /* Error functions. */ | 367 /* Error functions. */ |
380 #if 0 /* Leave these out unless we see they are worth having. */ | 368 #if 0 /* Leave these out unless we see they are worth having. */ |
381 /* #ifdef LISP_FLOAT_TYPE */ | 369 /* #ifdef LISP_FLOAT_TYPE */ |
382 | 370 |
383 DEFUN ("erf", Ferf, Serf, 1, 1, 0 /* | 371 DEFUN ("erf", Ferf, 1, 1, 0, /* |
384 Return the mathematical error function of ARG. | 372 Return the mathematical error function of ARG. |
385 */ ) | 373 */ |
386 (arg) | 374 (arg)) |
387 Lisp_Object arg; | |
388 { | 375 { |
389 double d = extract_float (arg); | 376 double d = extract_float (arg); |
390 IN_FLOAT (d = erf (d), "erf", arg); | 377 IN_FLOAT (d = erf (d), "erf", arg); |
391 return make_float (d); | 378 return make_float (d); |
392 } | 379 } |
393 | 380 |
394 DEFUN ("erfc", Ferfc, Serfc, 1, 1, 0 /* | 381 DEFUN ("erfc", Ferfc, 1, 1, 0, /* |
395 Return the complementary error function of ARG. | 382 Return the complementary error function of ARG. |
396 */ ) | 383 */ |
397 (arg) | 384 (arg)) |
398 Lisp_Object arg; | |
399 { | 385 { |
400 double d = extract_float (arg); | 386 double d = extract_float (arg); |
401 IN_FLOAT (d = erfc (d), "erfc", arg); | 387 IN_FLOAT (d = erfc (d), "erfc", arg); |
402 return make_float (d); | 388 return make_float (d); |
403 } | 389 } |
404 | 390 |
405 DEFUN ("log-gamma", Flog_gamma, Slog_gamma, 1, 1, 0 /* | 391 DEFUN ("log-gamma", Flog_gamma, 1, 1, 0, /* |
406 Return the log gamma of ARG. | 392 Return the log gamma of ARG. |
407 */ ) | 393 */ |
408 (arg) | 394 (arg)) |
409 Lisp_Object arg; | |
410 { | 395 { |
411 double d = extract_float (arg); | 396 double d = extract_float (arg); |
412 IN_FLOAT (d = lgamma (d), "log-gamma", arg); | 397 IN_FLOAT (d = lgamma (d), "log-gamma", arg); |
413 return make_float (d); | 398 return make_float (d); |
414 } | 399 } |
417 | 402 |
418 | 403 |
419 /* Root and Log functions. */ | 404 /* Root and Log functions. */ |
420 | 405 |
421 #ifdef LISP_FLOAT_TYPE | 406 #ifdef LISP_FLOAT_TYPE |
422 DEFUN ("exp", Fexp, Sexp, 1, 1, 0 /* | 407 DEFUN ("exp", Fexp, 1, 1, 0, /* |
423 Return the exponential base e of ARG. | 408 Return the exponential base e of ARG. |
424 */ ) | 409 */ |
425 (arg) | 410 (arg)) |
426 Lisp_Object arg; | |
427 { | 411 { |
428 double d = extract_float (arg); | 412 double d = extract_float (arg); |
429 #ifdef FLOAT_CHECK_DOMAIN | 413 #ifdef FLOAT_CHECK_DOMAIN |
430 if (d > 709.7827) /* Assume IEEE doubles here */ | 414 if (d > 709.7827) /* Assume IEEE doubles here */ |
431 range_error ("exp", arg); | 415 range_error ("exp", arg); |
437 return make_float (d); | 421 return make_float (d); |
438 } | 422 } |
439 #endif /* LISP_FLOAT_TYPE */ | 423 #endif /* LISP_FLOAT_TYPE */ |
440 | 424 |
441 | 425 |
442 DEFUN ("expt", Fexpt, Sexpt, 2, 2, 0 /* | 426 DEFUN ("expt", Fexpt, 2, 2, 0, /* |
443 Return the exponential ARG1 ** ARG2. | 427 Return the exponential ARG1 ** ARG2. |
444 */ ) | 428 */ |
445 (arg1, arg2) | 429 (arg1, arg2)) |
446 Lisp_Object arg1, arg2; | |
447 { | 430 { |
448 double f1, f2; | 431 double f1, f2; |
449 | 432 |
450 CHECK_INT_OR_FLOAT (arg1); | 433 CHECK_INT_OR_FLOAT (arg1); |
451 CHECK_INT_OR_FLOAT (arg2); | 434 CHECK_INT_OR_FLOAT (arg2); |
494 abort (); | 477 abort (); |
495 #endif /* LISP_FLOAT_TYPE */ | 478 #endif /* LISP_FLOAT_TYPE */ |
496 } | 479 } |
497 | 480 |
498 #ifdef LISP_FLOAT_TYPE | 481 #ifdef LISP_FLOAT_TYPE |
499 DEFUN ("log", Flog, Slog, 1, 2, 0 /* | 482 DEFUN ("log", Flog, 1, 2, 0, /* |
500 Return the natural logarithm of ARG. | 483 Return the natural logarithm of ARG. |
501 If second optional argument BASE is given, return log ARG using that base. | 484 If second optional argument BASE is given, return log ARG using that base. |
502 */ ) | 485 */ |
503 (arg, base) | 486 (arg, base)) |
504 Lisp_Object arg, base; | |
505 { | 487 { |
506 double d = extract_float (arg); | 488 double d = extract_float (arg); |
507 #ifdef FLOAT_CHECK_DOMAIN | 489 #ifdef FLOAT_CHECK_DOMAIN |
508 if (d <= 0.0) | 490 if (d <= 0.0) |
509 domain_error2 ("log", arg, base); | 491 domain_error2 ("log", arg, base); |
524 } | 506 } |
525 return make_float (d); | 507 return make_float (d); |
526 } | 508 } |
527 | 509 |
528 | 510 |
529 DEFUN ("log10", Flog10, Slog10, 1, 1, 0 /* | 511 DEFUN ("log10", Flog10, 1, 1, 0, /* |
530 Return the logarithm base 10 of ARG. | 512 Return the logarithm base 10 of ARG. |
531 */ ) | 513 */ |
532 (arg) | 514 (arg)) |
533 Lisp_Object arg; | |
534 { | 515 { |
535 double d = extract_float (arg); | 516 double d = extract_float (arg); |
536 #ifdef FLOAT_CHECK_DOMAIN | 517 #ifdef FLOAT_CHECK_DOMAIN |
537 if (d <= 0.0) | 518 if (d <= 0.0) |
538 domain_error ("log10", arg); | 519 domain_error ("log10", arg); |
540 IN_FLOAT (d = log10 (d), "log10", arg); | 521 IN_FLOAT (d = log10 (d), "log10", arg); |
541 return make_float (d); | 522 return make_float (d); |
542 } | 523 } |
543 | 524 |
544 | 525 |
545 DEFUN ("sqrt", Fsqrt, Ssqrt, 1, 1, 0 /* | 526 DEFUN ("sqrt", Fsqrt, 1, 1, 0, /* |
546 Return the square root of ARG. | 527 Return the square root of ARG. |
547 */ ) | 528 */ |
548 (arg) | 529 (arg)) |
549 Lisp_Object arg; | |
550 { | 530 { |
551 double d = extract_float (arg); | 531 double d = extract_float (arg); |
552 #ifdef FLOAT_CHECK_DOMAIN | 532 #ifdef FLOAT_CHECK_DOMAIN |
553 if (d < 0.0) | 533 if (d < 0.0) |
554 domain_error ("sqrt", arg); | 534 domain_error ("sqrt", arg); |
556 IN_FLOAT (d = sqrt (d), "sqrt", arg); | 536 IN_FLOAT (d = sqrt (d), "sqrt", arg); |
557 return make_float (d); | 537 return make_float (d); |
558 } | 538 } |
559 | 539 |
560 | 540 |
561 DEFUN ("cube-root", Fcube_root, Scube_root, 1, 1, 0 /* | 541 DEFUN ("cube-root", Fcube_root, 1, 1, 0, /* |
562 Return the cube root of ARG. | 542 Return the cube root of ARG. |
563 */ ) | 543 */ |
564 (arg) | 544 (arg)) |
565 Lisp_Object arg; | |
566 { | 545 { |
567 double d = extract_float (arg); | 546 double d = extract_float (arg); |
568 #ifdef HAVE_CBRT | 547 #ifdef HAVE_CBRT |
569 IN_FLOAT (d = cbrt (d), "cube-root", arg); | 548 IN_FLOAT (d = cbrt (d), "cube-root", arg); |
570 #else | 549 #else |
580 | 559 |
581 /* Inverse trig functions. */ | 560 /* Inverse trig functions. */ |
582 #ifdef LISP_FLOAT_TYPE | 561 #ifdef LISP_FLOAT_TYPE |
583 /* #if 0 Not clearly worth adding... */ | 562 /* #if 0 Not clearly worth adding... */ |
584 | 563 |
585 DEFUN ("acosh", Facosh, Sacosh, 1, 1, 0 /* | 564 DEFUN ("acosh", Facosh, 1, 1, 0, /* |
586 Return the inverse hyperbolic cosine of ARG. | 565 Return the inverse hyperbolic cosine of ARG. |
587 */ ) | 566 */ |
588 (arg) | 567 (arg)) |
589 Lisp_Object arg; | |
590 { | 568 { |
591 double d = extract_float (arg); | 569 double d = extract_float (arg); |
592 #ifdef FLOAT_CHECK_DOMAIN | 570 #ifdef FLOAT_CHECK_DOMAIN |
593 if (d < 1.0) | 571 if (d < 1.0) |
594 domain_error ("acosh", arg); | 572 domain_error ("acosh", arg); |
599 IN_FLOAT (d = log (d + sqrt (d*d - 1.0)), "acosh", arg); | 577 IN_FLOAT (d = log (d + sqrt (d*d - 1.0)), "acosh", arg); |
600 #endif | 578 #endif |
601 return make_float (d); | 579 return make_float (d); |
602 } | 580 } |
603 | 581 |
604 DEFUN ("asinh", Fasinh, Sasinh, 1, 1, 0 /* | 582 DEFUN ("asinh", Fasinh, 1, 1, 0, /* |
605 Return the inverse hyperbolic sine of ARG. | 583 Return the inverse hyperbolic sine of ARG. |
606 */ ) | 584 */ |
607 (arg) | 585 (arg)) |
608 Lisp_Object arg; | |
609 { | 586 { |
610 double d = extract_float (arg); | 587 double d = extract_float (arg); |
611 #ifdef HAVE_INVERSE_HYPERBOLIC | 588 #ifdef HAVE_INVERSE_HYPERBOLIC |
612 IN_FLOAT (d = asinh (d), "asinh", arg); | 589 IN_FLOAT (d = asinh (d), "asinh", arg); |
613 #else | 590 #else |
614 IN_FLOAT (d = log (d + sqrt (d*d + 1.0)), "asinh", arg); | 591 IN_FLOAT (d = log (d + sqrt (d*d + 1.0)), "asinh", arg); |
615 #endif | 592 #endif |
616 return make_float (d); | 593 return make_float (d); |
617 } | 594 } |
618 | 595 |
619 DEFUN ("atanh", Fatanh, Satanh, 1, 1, 0 /* | 596 DEFUN ("atanh", Fatanh, 1, 1, 0, /* |
620 Return the inverse hyperbolic tangent of ARG. | 597 Return the inverse hyperbolic tangent of ARG. |
621 */ ) | 598 */ |
622 (arg) | 599 (arg)) |
623 Lisp_Object arg; | |
624 { | 600 { |
625 double d = extract_float (arg); | 601 double d = extract_float (arg); |
626 #ifdef FLOAT_CHECK_DOMAIN | 602 #ifdef FLOAT_CHECK_DOMAIN |
627 if (d >= 1.0 || d <= -1.0) | 603 if (d >= 1.0 || d <= -1.0) |
628 domain_error ("atanh", arg); | 604 domain_error ("atanh", arg); |
633 IN_FLOAT (d = 0.5 * log ((1.0 + d) / (1.0 - d)), "atanh", arg); | 609 IN_FLOAT (d = 0.5 * log ((1.0 + d) / (1.0 - d)), "atanh", arg); |
634 #endif | 610 #endif |
635 return make_float (d); | 611 return make_float (d); |
636 } | 612 } |
637 | 613 |
638 DEFUN ("cosh", Fcosh, Scosh, 1, 1, 0 /* | 614 DEFUN ("cosh", Fcosh, 1, 1, 0, /* |
639 Return the hyperbolic cosine of ARG. | 615 Return the hyperbolic cosine of ARG. |
640 */ ) | 616 */ |
641 (arg) | 617 (arg)) |
642 Lisp_Object arg; | |
643 { | 618 { |
644 double d = extract_float (arg); | 619 double d = extract_float (arg); |
645 #ifdef FLOAT_CHECK_DOMAIN | 620 #ifdef FLOAT_CHECK_DOMAIN |
646 if (d > 710.0 || d < -710.0) | 621 if (d > 710.0 || d < -710.0) |
647 range_error ("cosh", arg); | 622 range_error ("cosh", arg); |
648 #endif | 623 #endif |
649 IN_FLOAT (d = cosh (d), "cosh", arg); | 624 IN_FLOAT (d = cosh (d), "cosh", arg); |
650 return make_float (d); | 625 return make_float (d); |
651 } | 626 } |
652 | 627 |
653 DEFUN ("sinh", Fsinh, Ssinh, 1, 1, 0 /* | 628 DEFUN ("sinh", Fsinh, 1, 1, 0, /* |
654 Return the hyperbolic sine of ARG. | 629 Return the hyperbolic sine of ARG. |
655 */ ) | 630 */ |
656 (arg) | 631 (arg)) |
657 Lisp_Object arg; | |
658 { | 632 { |
659 double d = extract_float (arg); | 633 double d = extract_float (arg); |
660 #ifdef FLOAT_CHECK_DOMAIN | 634 #ifdef FLOAT_CHECK_DOMAIN |
661 if (d > 710.0 || d < -710.0) | 635 if (d > 710.0 || d < -710.0) |
662 range_error ("sinh", arg); | 636 range_error ("sinh", arg); |
663 #endif | 637 #endif |
664 IN_FLOAT (d = sinh (d), "sinh", arg); | 638 IN_FLOAT (d = sinh (d), "sinh", arg); |
665 return make_float (d); | 639 return make_float (d); |
666 } | 640 } |
667 | 641 |
668 DEFUN ("tanh", Ftanh, Stanh, 1, 1, 0 /* | 642 DEFUN ("tanh", Ftanh, 1, 1, 0, /* |
669 Return the hyperbolic tangent of ARG. | 643 Return the hyperbolic tangent of ARG. |
670 */ ) | 644 */ |
671 (arg) | 645 (arg)) |
672 Lisp_Object arg; | |
673 { | 646 { |
674 double d = extract_float (arg); | 647 double d = extract_float (arg); |
675 IN_FLOAT (d = tanh (d), "tanh", arg); | 648 IN_FLOAT (d = tanh (d), "tanh", arg); |
676 return make_float (d); | 649 return make_float (d); |
677 } | 650 } |
678 #endif /* LISP_FLOAT_TYPE (inverse trig functions) */ | 651 #endif /* LISP_FLOAT_TYPE (inverse trig functions) */ |
679 | 652 |
680 /* Rounding functions */ | 653 /* Rounding functions */ |
681 | 654 |
682 DEFUN ("abs", Fabs, Sabs, 1, 1, 0 /* | 655 DEFUN ("abs", Fabs, 1, 1, 0, /* |
683 Return the absolute value of ARG. | 656 Return the absolute value of ARG. |
684 */ ) | 657 */ |
685 (arg) | 658 (arg)) |
686 Lisp_Object arg; | |
687 { | 659 { |
688 CHECK_INT_OR_FLOAT (arg); | 660 CHECK_INT_OR_FLOAT (arg); |
689 | 661 |
690 #ifdef LISP_FLOAT_TYPE | 662 #ifdef LISP_FLOAT_TYPE |
691 if (FLOATP (arg)) | 663 if (FLOATP (arg)) |
701 else | 673 else |
702 return (arg); | 674 return (arg); |
703 } | 675 } |
704 | 676 |
705 #ifdef LISP_FLOAT_TYPE | 677 #ifdef LISP_FLOAT_TYPE |
706 DEFUN ("float", Ffloat, Sfloat, 1, 1, 0 /* | 678 DEFUN ("float", Ffloat, 1, 1, 0, /* |
707 Return the floating point number equal to ARG. | 679 Return the floating point number equal to ARG. |
708 */ ) | 680 */ |
709 (arg) | 681 (arg)) |
710 Lisp_Object arg; | |
711 { | 682 { |
712 CHECK_INT_OR_FLOAT (arg); | 683 CHECK_INT_OR_FLOAT (arg); |
713 | 684 |
714 if (INTP (arg)) | 685 if (INTP (arg)) |
715 return make_float ((double) XINT (arg)); | 686 return make_float ((double) XINT (arg)); |
718 } | 689 } |
719 #endif /* LISP_FLOAT_TYPE */ | 690 #endif /* LISP_FLOAT_TYPE */ |
720 | 691 |
721 | 692 |
722 #ifdef LISP_FLOAT_TYPE | 693 #ifdef LISP_FLOAT_TYPE |
723 DEFUN ("logb", Flogb, Slogb, 1, 1, 0 /* | 694 DEFUN ("logb", Flogb, 1, 1, 0, /* |
724 Return largest integer <= the base 2 log of the magnitude of ARG. | 695 Return largest integer <= the base 2 log of the magnitude of ARG. |
725 This is the same as the exponent of a float. | 696 This is the same as the exponent of a float. |
726 */ ) | 697 */ |
727 (arg) | 698 (arg)) |
728 Lisp_Object arg; | |
729 { | 699 { |
730 double f = extract_float (arg); | 700 double f = extract_float (arg); |
731 | 701 |
732 if (f == 0.0) | 702 if (f == 0.0) |
733 return (make_int (- (((EMACS_UINT) 1) << (VALBITS - 1)))); /* most-negative-fixnum */ | 703 return (make_int (- (((EMACS_UINT) 1) << (VALBITS - 1)))); /* most-negative-fixnum */ |
772 #endif /* ! HAVE_LOGB */ | 742 #endif /* ! HAVE_LOGB */ |
773 } | 743 } |
774 #endif /* LISP_FLOAT_TYPE */ | 744 #endif /* LISP_FLOAT_TYPE */ |
775 | 745 |
776 | 746 |
777 DEFUN ("ceiling", Fceiling, Sceiling, 1, 1, 0 /* | 747 DEFUN ("ceiling", Fceiling, 1, 1, 0, /* |
778 Return the smallest integer no less than ARG. (Round toward +inf.) | 748 Return the smallest integer no less than ARG. (Round toward +inf.) |
779 */ ) | 749 */ |
780 (arg) | 750 (arg)) |
781 Lisp_Object arg; | |
782 { | 751 { |
783 CHECK_INT_OR_FLOAT (arg); | 752 CHECK_INT_OR_FLOAT (arg); |
784 | 753 |
785 #ifdef LISP_FLOAT_TYPE | 754 #ifdef LISP_FLOAT_TYPE |
786 if (FLOATP (arg)) | 755 if (FLOATP (arg)) |
793 | 762 |
794 return arg; | 763 return arg; |
795 } | 764 } |
796 | 765 |
797 | 766 |
798 DEFUN ("floor", Ffloor, Sfloor, 1, 2, 0 /* | 767 DEFUN ("floor", Ffloor, 1, 2, 0, /* |
799 Return the largest integer no greater than ARG. (Round towards -inf.) | 768 Return the largest integer no greater than ARG. (Round towards -inf.) |
800 With optional DIVISOR, return the largest integer no greater than ARG/DIVISOR. | 769 With optional DIVISOR, return the largest integer no greater than ARG/DIVISOR. |
801 */ ) | 770 */ |
802 (arg, divisor) | 771 (arg, divisor)) |
803 Lisp_Object arg, divisor; | |
804 { | 772 { |
805 CHECK_INT_OR_FLOAT (arg); | 773 CHECK_INT_OR_FLOAT (arg); |
806 | 774 |
807 if (! NILP (divisor)) | 775 if (! NILP (divisor)) |
808 { | 776 { |
850 #endif /* LISP_FLOAT_TYPE */ | 818 #endif /* LISP_FLOAT_TYPE */ |
851 | 819 |
852 return arg; | 820 return arg; |
853 } | 821 } |
854 | 822 |
855 DEFUN ("round", Fround, Sround, 1, 1, 0 /* | 823 DEFUN ("round", Fround, 1, 1, 0, /* |
856 Return the nearest integer to ARG. | 824 Return the nearest integer to ARG. |
857 */ ) | 825 */ |
858 (arg) | 826 (arg)) |
859 Lisp_Object arg; | |
860 { | 827 { |
861 CHECK_INT_OR_FLOAT (arg); | 828 CHECK_INT_OR_FLOAT (arg); |
862 | 829 |
863 #ifdef LISP_FLOAT_TYPE | 830 #ifdef LISP_FLOAT_TYPE |
864 if (FLOATP (arg)) | 831 if (FLOATP (arg)) |
871 #endif /* LISP_FLOAT_TYPE */ | 838 #endif /* LISP_FLOAT_TYPE */ |
872 | 839 |
873 return arg; | 840 return arg; |
874 } | 841 } |
875 | 842 |
876 DEFUN ("truncate", Ftruncate, Struncate, 1, 1, 0 /* | 843 DEFUN ("truncate", Ftruncate, 1, 1, 0, /* |
877 Truncate a floating point number to an integer. | 844 Truncate a floating point number to an integer. |
878 Rounds the value toward zero. | 845 Rounds the value toward zero. |
879 */ ) | 846 */ |
880 (arg) | 847 (arg)) |
881 Lisp_Object arg; | |
882 { | 848 { |
883 CHECK_INT_OR_FLOAT (arg); | 849 CHECK_INT_OR_FLOAT (arg); |
884 | 850 |
885 #ifdef LISP_FLOAT_TYPE | 851 #ifdef LISP_FLOAT_TYPE |
886 if (FLOATP (arg)) | 852 if (FLOATP (arg)) |
893 | 859 |
894 /* Float-rounding functions. */ | 860 /* Float-rounding functions. */ |
895 #ifdef LISP_FLOAT_TYPE | 861 #ifdef LISP_FLOAT_TYPE |
896 /* #if 1 It's not clear these are worth adding... */ | 862 /* #if 1 It's not clear these are worth adding... */ |
897 | 863 |
898 DEFUN ("fceiling", Ffceiling, Sfceiling, 1, 1, 0 /* | 864 DEFUN ("fceiling", Ffceiling, 1, 1, 0, /* |
899 Return the smallest integer no less than ARG, as a float. | 865 Return the smallest integer no less than ARG, as a float. |
900 \(Round toward +inf.\) | 866 \(Round toward +inf.\) |
901 */ ) | 867 */ |
902 (arg) | 868 (arg)) |
903 Lisp_Object arg; | |
904 { | 869 { |
905 double d = extract_float (arg); | 870 double d = extract_float (arg); |
906 IN_FLOAT (d = ceil (d), "fceiling", arg); | 871 IN_FLOAT (d = ceil (d), "fceiling", arg); |
907 return make_float (d); | 872 return make_float (d); |
908 } | 873 } |
909 | 874 |
910 DEFUN ("ffloor", Fffloor, Sffloor, 1, 1, 0 /* | 875 DEFUN ("ffloor", Fffloor, 1, 1, 0, /* |
911 Return the largest integer no greater than ARG, as a float. | 876 Return the largest integer no greater than ARG, as a float. |
912 \(Round towards -inf.\) | 877 \(Round towards -inf.\) |
913 */ ) | 878 */ |
914 (arg) | 879 (arg)) |
915 Lisp_Object arg; | |
916 { | 880 { |
917 double d = extract_float (arg); | 881 double d = extract_float (arg); |
918 IN_FLOAT (d = floor (d), "ffloor", arg); | 882 IN_FLOAT (d = floor (d), "ffloor", arg); |
919 return make_float (d); | 883 return make_float (d); |
920 } | 884 } |
921 | 885 |
922 DEFUN ("fround", Ffround, Sfround, 1, 1, 0 /* | 886 DEFUN ("fround", Ffround, 1, 1, 0, /* |
923 Return the nearest integer to ARG, as a float. | 887 Return the nearest integer to ARG, as a float. |
924 */ ) | 888 */ |
925 (arg) | 889 (arg)) |
926 Lisp_Object arg; | |
927 { | 890 { |
928 double d = extract_float (arg); | 891 double d = extract_float (arg); |
929 IN_FLOAT (d = rint (d), "fround", arg); | 892 IN_FLOAT (d = rint (d), "fround", arg); |
930 return make_float (d); | 893 return make_float (d); |
931 } | 894 } |
932 | 895 |
933 DEFUN ("ftruncate", Fftruncate, Sftruncate, 1, 1, 0 /* | 896 DEFUN ("ftruncate", Fftruncate, 1, 1, 0, /* |
934 Truncate a floating point number to an integral float value. | 897 Truncate a floating point number to an integral float value. |
935 Rounds the value toward zero. | 898 Rounds the value toward zero. |
936 */ ) | 899 */ |
937 (arg) | 900 (arg)) |
938 Lisp_Object arg; | |
939 { | 901 { |
940 double d = extract_float (arg); | 902 double d = extract_float (arg); |
941 if (d >= 0.0) | 903 if (d >= 0.0) |
942 IN_FLOAT (d = floor (d), "ftruncate", arg); | 904 IN_FLOAT (d = floor (d), "ftruncate", arg); |
943 else | 905 else |
1019 { | 981 { |
1020 | 982 |
1021 /* Trig functions. */ | 983 /* Trig functions. */ |
1022 | 984 |
1023 #ifdef LISP_FLOAT_TYPE | 985 #ifdef LISP_FLOAT_TYPE |
1024 defsubr (&Sacos); | 986 DEFSUBR (Facos); |
1025 defsubr (&Sasin); | 987 DEFSUBR (Fasin); |
1026 defsubr (&Satan); | 988 DEFSUBR (Fatan); |
1027 defsubr (&Scos); | 989 DEFSUBR (Fcos); |
1028 defsubr (&Ssin); | 990 DEFSUBR (Fsin); |
1029 defsubr (&Stan); | 991 DEFSUBR (Ftan); |
1030 #endif /* LISP_FLOAT_TYPE */ | 992 #endif /* LISP_FLOAT_TYPE */ |
1031 | 993 |
1032 /* Bessel functions */ | 994 /* Bessel functions */ |
1033 | 995 |
1034 #if 0 | 996 #if 0 |
1035 defsubr (&Sbessel_y0); | 997 DEFSUBR (Fbessel_y0); |
1036 defsubr (&Sbessel_y1); | 998 DEFSUBR (Fbessel_y1); |
1037 defsubr (&Sbessel_yn); | 999 DEFSUBR (Fbessel_yn); |
1038 defsubr (&Sbessel_j0); | 1000 DEFSUBR (Fbessel_j0); |
1039 defsubr (&Sbessel_j1); | 1001 DEFSUBR (Fbessel_j1); |
1040 defsubr (&Sbessel_jn); | 1002 DEFSUBR (Fbessel_jn); |
1041 #endif /* 0 */ | 1003 #endif /* 0 */ |
1042 | 1004 |
1043 /* Error functions. */ | 1005 /* Error functions. */ |
1044 | 1006 |
1045 #if 0 | 1007 #if 0 |
1046 defsubr (&Serf); | 1008 DEFSUBR (Ferf); |
1047 defsubr (&Serfc); | 1009 DEFSUBR (Ferfc); |
1048 defsubr (&Slog_gamma); | 1010 DEFSUBR (Flog_gamma); |
1049 #endif /* 0 */ | 1011 #endif /* 0 */ |
1050 | 1012 |
1051 /* Root and Log functions. */ | 1013 /* Root and Log functions. */ |
1052 | 1014 |
1053 #ifdef LISP_FLOAT_TYPE | 1015 #ifdef LISP_FLOAT_TYPE |
1054 defsubr (&Sexp); | 1016 DEFSUBR (Fexp); |
1055 #endif /* LISP_FLOAT_TYPE */ | 1017 #endif /* LISP_FLOAT_TYPE */ |
1056 defsubr (&Sexpt); | 1018 DEFSUBR (Fexpt); |
1057 #ifdef LISP_FLOAT_TYPE | 1019 #ifdef LISP_FLOAT_TYPE |
1058 defsubr (&Slog); | 1020 DEFSUBR (Flog); |
1059 defsubr (&Slog10); | 1021 DEFSUBR (Flog10); |
1060 defsubr (&Ssqrt); | 1022 DEFSUBR (Fsqrt); |
1061 defsubr (&Scube_root); | 1023 DEFSUBR (Fcube_root); |
1062 #endif /* LISP_FLOAT_TYPE */ | 1024 #endif /* LISP_FLOAT_TYPE */ |
1063 | 1025 |
1064 /* Inverse trig functions. */ | 1026 /* Inverse trig functions. */ |
1065 | 1027 |
1066 #ifdef LISP_FLOAT_TYPE | 1028 #ifdef LISP_FLOAT_TYPE |
1067 defsubr (&Sacosh); | 1029 DEFSUBR (Facosh); |
1068 defsubr (&Sasinh); | 1030 DEFSUBR (Fasinh); |
1069 defsubr (&Satanh); | 1031 DEFSUBR (Fatanh); |
1070 defsubr (&Scosh); | 1032 DEFSUBR (Fcosh); |
1071 defsubr (&Ssinh); | 1033 DEFSUBR (Fsinh); |
1072 defsubr (&Stanh); | 1034 DEFSUBR (Ftanh); |
1073 #endif /* LISP_FLOAT_TYPE */ | 1035 #endif /* LISP_FLOAT_TYPE */ |
1074 | 1036 |
1075 /* Rounding functions */ | 1037 /* Rounding functions */ |
1076 | 1038 |
1077 defsubr (&Sabs); | 1039 DEFSUBR (Fabs); |
1078 #ifdef LISP_FLOAT_TYPE | 1040 #ifdef LISP_FLOAT_TYPE |
1079 defsubr (&Sfloat); | 1041 DEFSUBR (Ffloat); |
1080 defsubr (&Slogb); | 1042 DEFSUBR (Flogb); |
1081 #endif /* LISP_FLOAT_TYPE */ | 1043 #endif /* LISP_FLOAT_TYPE */ |
1082 defsubr (&Sceiling); | 1044 DEFSUBR (Fceiling); |
1083 defsubr (&Sfloor); | 1045 DEFSUBR (Ffloor); |
1084 defsubr (&Sround); | 1046 DEFSUBR (Fround); |
1085 defsubr (&Struncate); | 1047 DEFSUBR (Ftruncate); |
1086 | 1048 |
1087 /* Float-rounding functions. */ | 1049 /* Float-rounding functions. */ |
1088 | 1050 |
1089 #ifdef LISP_FLOAT_TYPE | 1051 #ifdef LISP_FLOAT_TYPE |
1090 defsubr (&Sfceiling); | 1052 DEFSUBR (Ffceiling); |
1091 defsubr (&Sffloor); | 1053 DEFSUBR (Fffloor); |
1092 defsubr (&Sfround); | 1054 DEFSUBR (Ffround); |
1093 defsubr (&Sftruncate); | 1055 DEFSUBR (Fftruncate); |
1094 #endif /* LISP_FLOAT_TYPE */ | 1056 #endif /* LISP_FLOAT_TYPE */ |
1095 } | 1057 } |
1096 | 1058 |
1097 void | 1059 void |
1098 vars_of_floatfns (void) | 1060 vars_of_floatfns (void) |