Steel Bank Common Lisp

cos/sin return zero for large values on x86

Reported by Gábor Melis on 2009-02-09
2
Affects Status Importance Assigned to Milestone
SBCL
Medium
Paul Khuong

Bug Description

(sin (expt 2d0 65)) => 0.0d0
(cos (expt 2d0 65)) => 0.0d0
(tan (expt 2d0 65))

debugger invoked on a FLOATING-POINT-INVALID-OPERATION in thread #<THREAD "initial thread" RUNNING {A8B0699}>:
  arithmetic error FLOATING-POINT-INVALID-OPERATION signalled

Type HELP for debugger help, or (SB-EXT:QUIT) to exit from SBCL.

restarts (invokable by number or by possibly-abbreviated name):
  0: [ABORT] Exit debugger, returning to top level.

((FLET SB-UNIX::%WRITE) #.(SB-SYS:INT-SAP #XB7FDC000))
0] ba

0: ((FLET SB-UNIX::%WRITE) #.(SB-SYS:INT-SAP #XB7FDC000))
1: (SB-UNIX:UNIX-WRITE 1 #.(SB-SYS:INT-SAP #XB7FDC000) 0 1)[:EXTERNAL]
2: (SB-IMPL::FLUSH-OUTPUT-BUFFER
    #<SB-SYS:FD-STREAM for "standard output" {A8B0989}>)
3: (SB-IMPL::OUTPUT-CHAR-UTF-8-LINE-BUFFERED
    #<SB-SYS:FD-STREAM for "standard output" {A8B0989}>
    #\Newline)
4: (WRITE-CHAR #\Newline #<SB-SYS:FD-STREAM for "standard output" {A8B0989}>)
5: (FRESH-LINE #<SYNONYM-STREAM :SYMBOL SB-SYS:*STDOUT* {910AD01}>)
6: (SB-IMPL::REPL-FUN NIL)
7: ((LAMBDA ()))
8: (SB-IMPL::%WITH-REBOUND-IO-SYNTAX #<CLOSURE (LAMBDA #) {B3F95CD}>)
9: (SB-IMPL::TOPLEVEL-REPL NIL)
10: (SB-IMPL::TOPLEVEL-INIT)
11: ((LABELS SB-IMPL::RESTART-LISP))

---------------

They behave correctly on all other platforms including x86-64 since those use alien functions and don't have %sin, %sin-quick , etc VOPs. Reproduced on 0.9.0.6, 1.0.18, 1.0.25.10.

Gábor Melis (melisgl) wrote :

Even if the VOPs were correct, %SIN-QUICK & co should only be used when the argument is betwen (expt 2d0 -63) and (expt 2d0 63) and not 64 as the deftransform thinks.

Gábor Melis (melisgl) wrote :

... make that (- (expt 2d0 63))

Changed in sbcl:
importance: Undecided → Medium
status: New → Confirmed
Gustavo (gugamilare) wrote :

What about implementing an expansion of sin like this:

(sin x) => (%sin (mod x (* 2 pi)))

? I don't know how sin and cos are implemented, but the standard implementation using power series converge faster for smaller values (am I right?), so this could be a good thing. Or am I missing something?

Paul Khuong (pvk) on 2009-08-04
Changed in sbcl:
assignee: nobody → Paul Khuong (pvk)
status: Confirmed → In Progress
Paul Khuong (pvk) on 2010-04-26
Changed in sbcl:
status: In Progress → Fix Committed
Changed in sbcl:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers