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

Use setexception to raise the inexact exception for sin.

parent d448ca78
No related branches found
No related tags found
No related merge requests found
...@@ -67,8 +67,14 @@ S6 = 1.58969099521155010221e-10; /* 0x3DE5D93A, 0x5ACFD57C */ ...@@ -67,8 +67,14 @@ S6 = 1.58969099521155010221e-10; /* 0x3DE5D93A, 0x5ACFD57C */
ux.d = x; ux.d = x;
ix = ux.i[HIWORD]&0x7fffffff; /* high word of x */ ix = ux.i[HIWORD]&0x7fffffff; /* high word of x */
if(ix<0x3e400000) /* |x| < 2**-27 */ if(ix<0x3e400000) { /* |x| < 2**-27 */
{if((int)x==0) return x;} /* generate inexact */ /* return x inexact except 0 */
if (x != 0) {
fdlibm_setexception(x, FDLIBM_INEXACT);
}
return x;
}
z = x*x; z = x*x;
v = z*x; v = z*x;
r = S2+z*(S3+z*(S4+z*(S5+z*S6))); r = S2+z*(S3+z*(S4+z*(S5+z*S6)));
......
...@@ -622,3 +622,19 @@ ...@@ -622,3 +622,19 @@
;; though the result is exactly x. ;; though the result is exactly x.
(assert-error 'floating-point-inexact (assert-error 'floating-point-inexact
(kernel:%cos x))))) (kernel:%cos x)))))
(define-test %sin.exceptions
(:tag :fdlibm)
;; sin(x) = x 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 0d0 (kernel:%sin 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:%sin 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