Raymond Toy pushed to branch issue-425-correctly-rounded-math-functions-single-float at cmucl / cmucl

Commits:

1 changed file:

Changes:

  • tests/fdlibm.lisp
    ... ... @@ -440,6 +440,39 @@
    440 440
     	(assert-error 'floating-point-inexact
    
    441 441
     		      (kernel:%exp x)))))
    
    442 442
     
    
    443
    +(define-test %expf.exceptions
    
    444
    +  (:tag :fdlibm)
    
    445
    +  (assert-error 'floating-point-overflow
    
    446
    +		(kernel:%expf 89f0))
    
    447
    +  (assert-true (ext:float-nan-p (kernel:%expf *qnan-single-float*)))
    
    448
    +  (assert-error 'floating-point-invalid-operation
    
    449
    +		(kernel:%expf *snan-single-float*))
    
    450
    +  (assert-equal ext:single-float-positive-infinity
    
    451
    +		(kernel:%expf ext:single-float-positive-infinity))
    
    452
    +  (assert-equal 0f0
    
    453
    +		(kernel:%expf -200f0))
    
    454
    +  (ext:with-float-traps-masked (:overflow)
    
    455
    +    (assert-equal ext:single-float-positive-infinity
    
    456
    +		  (kernel:%expf 89f0)))
    
    457
    +  (ext:with-float-traps-enabled (:underflow)
    
    458
    +    (assert-error 'floating-point-underflow
    
    459
    +		  (kernel:%expf -200f0)))
    
    460
    +
    
    461
    +  (let ((x (scale-float 1f0 -13))
    
    462
    +	(x0 0f0))
    
    463
    +    ;; exp(x) = 1 + x, |x| < 2^-12, with inexact exception unlees x =
    
    464
    +    ;; 0.  The actual threshold is closer to sqrt(2*eps) or about
    
    465
    +    ;; 2.44e-4, about 2^-12
    
    466
    +    (ext:with-float-traps-enabled (:inexact)
    
    467
    +	;; This must not throw an inexact exception because the result
    
    468
    +	;; is exact when the arg is 0.
    
    469
    +	(assert-eql 1f0 (kernel:%expf x0)))
    
    470
    +    (ext:with-float-traps-enabled (:inexact)
    
    471
    +	;; This must throw an inexact exception for non-zero x even
    
    472
    +	;; though the result is exactly x.
    
    473
    +	(assert-error 'floating-point-inexact
    
    474
    +		      (kernel:%expf x)))))
    
    475
    +
    
    443 476
     (define-test %log.exception
    
    444 477
       (:tag :fdlibm)
    
    445 478
       (assert-error 'division-by-zero
    
    ... ... @@ -460,6 +493,26 @@
    460 493
         (assert-true (ext:float-nan-p (kernel:%log -1d0)))
    
    461 494
         (assert-true (ext:float-nan-p (kernel:%log *snan*)))))
    
    462 495
     
    
    496
    +(define-test %logf.exception
    
    497
    +  (:tag :fdlibm)
    
    498
    +  (assert-error 'division-by-zero
    
    499
    +		(kernel:%logf 0f0))
    
    500
    +  (assert-error 'division-by-zero
    
    501
    +		(kernel:%logf -0f0))
    
    502
    +  (assert-error 'floating-point-invalid-operation
    
    503
    +		(kernel:%logf -1f0))
    
    504
    +  (assert-error 'floating-point-invalid-operation
    
    505
    +		(kernel:%logf *snan-single-float*))
    
    506
    +  (assert-true (ext:float-nan-p (kernel:%logf *qnan-single-float*)))
    
    507
    +  (ext:with-float-traps-masked (:divide-by-zero)
    
    508
    +    (assert-equal ext:single-float-negative-infinity
    
    509
    +		  (kernel:%logf 0f0))
    
    510
    +    (assert-equal ext:single-float-negative-infinity
    
    511
    +		  (kernel:%logf -0f0)))
    
    512
    +  (ext:with-float-traps-masked (:invalid)
    
    513
    +    (assert-true (ext:float-nan-p (kernel:%logf -1f0)))
    
    514
    +    (assert-true (ext:float-nan-p (kernel:%logf *snan-single-float*)))))
    
    515
    +
    
    463 516
     (define-test %acos.exceptions
    
    464 517
       (:tag :fdlibm)
    
    465 518
       (assert-error 'floating-point-invalid-operation
    
    ... ... @@ -470,6 +523,16 @@
    470 523
         (assert-true (ext:float-nan-p (kernel:%acos 2d0)))
    
    471 524
         (assert-true (ext:float-nan-p (kernel:%acos -2d0)))))
    
    472 525
     
    
    526
    +(define-test %acosf.exceptions
    
    527
    +  (:tag :fdlibm)
    
    528
    +  (assert-error 'floating-point-invalid-operation
    
    529
    +		(kernel:%acosf 2f0))
    
    530
    +  (assert-error 'floating-point-invalid-operation
    
    531
    +		(kernel:%acosf -2f0))
    
    532
    +  (ext:with-float-traps-masked (:invalid)
    
    533
    +    (assert-true (ext:float-nan-p (kernel:%acosf 2f0)))
    
    534
    +    (assert-true (ext:float-nan-p (kernel:%acosf -2f0)))))
    
    535
    +
    
    473 536
     (define-test %asin.exceptions
    
    474 537
       (:tag :fdlibm)
    
    475 538
       (assert-error 'floating-point-invalid-operation
    
    ... ... @@ -480,6 +543,16 @@
    480 543
         (assert-true (ext:float-nan-p (kernel:%asin 2d0)))
    
    481 544
         (assert-true (ext:float-nan-p (kernel:%asin -2d0)))))
    
    482 545
     
    
    546
    +(define-test %asinf.exceptions
    
    547
    +  (:tag :fdlibm)
    
    548
    +  (assert-error 'floating-point-invalid-operation
    
    549
    +		(kernel:%asinf 2f0))
    
    550
    +  (assert-error 'floating-point-invalid-operation
    
    551
    +		(kernel:%asinf -2f0))
    
    552
    +  (ext:with-float-traps-masked (:invalid)
    
    553
    +    (assert-true (ext:float-nan-p (kernel:%asinf 2f0)))
    
    554
    +    (assert-true (ext:float-nan-p (kernel:%asinf -2f0)))))
    
    555
    +
    
    483 556
     (define-test %atan.exceptions
    
    484 557
       (:tag :fdlibm)
    
    485 558
       (assert-error 'floating-point-invalid-operation
    
    ... ... @@ -500,6 +573,26 @@
    500 573
     	(assert-error 'floating-point-inexact
    
    501 574
     		      (kernel:%atan x)))))
    
    502 575
     
    
    576
    +(define-test %atanf.exceptions
    
    577
    +  (:tag :fdlibm)
    
    578
    +  (assert-error 'floating-point-invalid-operation
    
    579
    +		(kernel:%atanf *snan-single-float*))
    
    580
    +  (assert-true (ext:float-nan-p (kernel:%atanf *qnan-single-float*)))
    
    581
    +  (ext:with-float-traps-masked (:invalid)
    
    582
    +    (assert-true (ext:float-nan-p (kernel:%atanf *snan-single-float*))))
    
    583
    +  ;; atan(x) = x for small x, signaling inexact except when x = 0.
    
    584
    +  (let ((x (scale-float 1f0 -30))
    
    585
    +	(x0 0f0))
    
    586
    +    (ext:with-float-traps-enabled (:inexact)
    
    587
    +	;; This must not throw an inexact exception because the result
    
    588
    +	;; is exact when the arg is 0.
    
    589
    +	(assert-eql 0f0 (kernel:%atanf x0)))
    
    590
    +    (ext:with-float-traps-enabled (:inexact)
    
    591
    +	;; This must throw an inexact exception for non-zero x even
    
    592
    +	;; though the result is exactly x.
    
    593
    +	(assert-error 'floating-point-inexact
    
    594
    +		      (kernel:%atanf x)))))
    
    595
    +
    
    503 596
     (define-test %log10.exceptions
    
    504 597
       (:tag :fdlibm)
    
    505 598
       ;; %log10(2^k) = k
    
    ... ... @@ -521,6 +614,27 @@
    521 614
       (ext:with-float-traps-masked (:invalid)
    
    522 615
         (assert-true (ext:float-nan-p (kernel:%log10 -1d0)))))
    
    523 616
     
    
    617
    +(define-test %log10f.exceptions
    
    618
    +  (:tag :fdlibm)
    
    619
    +  ;; %log10(2^k) = k
    
    620
    +  (dotimes (k 23)
    
    621
    +    (assert-equalp k
    
    622
    +		  (kernel:%log10f (float (expt 10 k) 1f0))))
    
    623
    +  (assert-error 'division-by-zero
    
    624
    +		(kernel:%log10f 0f0))
    
    625
    +  (assert-error 'floating-point-invalid-operation
    
    626
    +		(kernel:%log10f -1f0))
    
    627
    +  (assert-true (ext:float-nan-p (kernel:%log10f *qnan-single-float*)))
    
    628
    +  (assert-equal ext:single-float-positive-infinity
    
    629
    +		(kernel:%log10f ext:single-float-positive-infinity))
    
    630
    +  (ext:with-float-traps-masked (:divide-by-zero)
    
    631
    +    (assert-equal ext:single-float-negative-infinity
    
    632
    +		  (kernel:%log10f 0f0))
    
    633
    +    (assert-equal ext:single-float-negative-infinity
    
    634
    +		  (kernel:%log10f -0f0)))
    
    635
    +  (ext:with-float-traps-masked (:invalid)
    
    636
    +    (assert-true (ext:float-nan-p (kernel:%log10f -1f0)))))
    
    637
    +
    
    524 638
     (define-test %scalbn.exceptions
    
    525 639
       (:tag :fdlibm)
    
    526 640
       (let ((modes (ext:get-floating-point-modes)))