Skip to content
Snippets Groups Projects
Commit d448ca78 authored by Raymond Toy's avatar Raymond Toy
Browse files

Use setexception to raise the inexact exception for cos.

parent e90e91d4
No related branches found
No related tags found
No related merge requests found
...@@ -75,7 +75,12 @@ C6 = -1.13596475577881948265e-11; /* 0xBDA8FAE9, 0xBE8838D4 */ ...@@ -75,7 +75,12 @@ C6 = -1.13596475577881948265e-11; /* 0xBDA8FAE9, 0xBE8838D4 */
ux.d = x; ux.d = x;
ix = ux.i[HIWORD]&0x7fffffff; /* ix = |x|'s high word*/ ix = ux.i[HIWORD]&0x7fffffff; /* ix = |x|'s high word*/
if(ix<0x3e400000) { /* if x < 2**27 */ if(ix<0x3e400000) { /* if x < 2**27 */
if(((int)x)==0) return one; /* generate inexact */ /* return 1 with inexact unless x == 0 */
if (x != 0) {
fdlibm_setexception(x, FDLIBM_INEXACT);
}
return one;
} }
z = x*x; z = x*x;
r = z*(C1+z*(C2+z*(C3+z*(C4+z*(C5+z*C6))))); r = z*(C1+z*(C2+z*(C3+z*(C4+z*(C5+z*C6)))));
......
...@@ -608,3 +608,17 @@ ...@@ -608,3 +608,17 @@
(assert-error 'floating-point-inexact (assert-error 'floating-point-inexact
(kernel:%asin x))))) (kernel:%asin x)))))
(define-test %cos.exceptions
(:tag :fdlibm)
;; cos(x) = 1 for |x| < 2^-27. Signal inexact unless x = 0
(let ((x (scale-float 1d0 -28))
(x0 0d0))
(with-inexact-exception-enabled
;; This must not throw an inexact exception because the result
;; is exact when the arg is 0.
(assert-eql 1d0 (kernel:%cos x0)))
(with-inexact-exception-enabled
;; This must throw an inexact exception for non-zero x even
;; though the result is exactly x.
(assert-error 'floating-point-inexact
(kernel:%cos x)))))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment