david135 / ypsilon

Automatically exported from code.google.com/p/ypsilon
Other
0 stars 0 forks source link

fxrotate-bit-field broken #89

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
`fxrotate-bit-field' uses the implementation from R6RS, which was
corrected in the R6RS errata[1]; this leads to failure in some cases:

    Ypsilon 0.9.6-trunk/r416 Copyright (c) 2009 Y.Fujita, LittleWing
Company Limited.
    > (fxrotate-bit-field #b10 0 (- (fixnum-width) 1) (- (fixnum-width) 2))
    error in fxarithmetic-shift-left: return value out of fixnum range
4611686018427387904

    irritants:
      (2 61)

For example, Ikarus gets this right:

    Ikarus Scheme version 0.0.4-rc1+, 64-bit (revision 1747, build 2009-04-02)
    Copyright (c) 2006-2008 Abdulaziz Ghuloum

    > (fxrotate-bit-field #b10 0 (- (fixnum-width) 1) (- (fixnum-width) 2))
    1  

The fix is easy, just use the implementation from the errata (patch
attached). On a related note, `fxarithmetic-shift-left' fails to raise
`&implementation-restriction' in some cases (when the shift done in
the C code produces a result in the fixnum range due to shifting
approriate bits out, e.g:

    > (fxarithmetic-shift (fxarithmetic-shift #b11 (- (fixnum-width) 3)) 6)
    0   

while:

    > (fxarithmetic-shift (fxarithmetic-shift #b11 (- (fixnum-width) 3)) 1)

    error in fxarithmetic-shift: return value out of fixnum range
6917529027641081856

    irritants:
      (3458764513820540928 1)

I just tried this in Ikarus, and it seems it *never* raises an
`&implementation-restriction' for `fxarithmetic-shift' -- is this a
bug, or does R6RS allow some leeway here?

Original issue reported on code.google.com by rott...@gmail.com on 3 Apr 2009 at 5:01

Attachments:

GoogleCodeExporter commented 9 years ago
Thank you for your bug report!
-- fujita

Original comment by y.fujita...@gmail.com on 6 Apr 2009 at 10:51

GoogleCodeExporter commented 9 years ago
I have fixed the bug and trunk directory is updated to revision 417.

Ypsilon 0.9.6-trunk/r417 Copyright (c) 2009 Y.Fujita, LittleWing Company 
Limited.
> (fxrotate-bit-field #b10 0 (- (fixnum-width) 1) (- (fixnum-width) 2))
1

Regarding fxarithmetic-shift,
I think (fxarithmetic-shift (fxarithmetic-shift #b11 (- (fixnum-width) 3)) 6) 
should
raises `&implementation-restriction'.
Reference: 
http://www.r6rs.org/final/html/r6rs-lib/r6rs-lib-Z-H-12.html#node_idx_938

That bug also fixed in revision 417.

Ypsilon 0.9.6-trunk/r417 Copyright (c) 2009 Y.Fujita, LittleWing Company 
Limited.
> (fxarithmetic-shift (fxarithmetic-shift #b11 (- (fixnum-width) 3)) 1)

error in fxarithmetic-shift: return value out of fixnum range 1610612736

irritants:
  (805306368 1)

backtrace:
  0  (fxarithmetic-shift (fxarithmetic-shift 3 (- (fixnum-width) 3)) 1)
  ..."/dev/stdin" line 1

> (fxarithmetic-shift (fxarithmetic-shift #b11 (- (fixnum-width) 3)) 6)

error in fxarithmetic-shift: return value out of fixnum range 51539607552

irritants:
  (805306368 6)

backtrace:
  0  (fxarithmetic-shift (fxarithmetic-shift 3 (- (fixnum-width) 3)) 6)
  ..."/dev/stdin" line 1

Please try. Thank you!
--fujita

Original comment by y.fujita...@gmail.com on 6 Apr 2009 at 2:01