Changeset 26595 in project


Ignore:
Timestamp:
04/29/12 17:47:38 (8 years ago)
Author:
sjamaan
Message:

numbers: Fix 'rationalize' return type to be inexact when given an inexact input

Location:
release/4/numbers/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • release/4/numbers/trunk/numbers.scm

    r26581 r26595  
    13631363(define (find-ratio x e) (find-ratio-between (%- x e) (%+ x e)))
    13641364
    1365 (define (rationalize x e) (apply %/ (find-ratio x e))) ; doesn't preserve exactness
     1365(define (rationalize x e)
     1366  (let ((result (apply %/ (find-ratio x e))))
     1367    (if (or (inexact? x) (inexact? e))
     1368        (exact->inexact result)
     1369        result)))
    13661370
    13671371(define (%exp n)
  • release/4/numbers/trunk/tests/numbers-test.scm

    r26584 r26595  
    750750 (test "round" 7 (round 7))
    751751
    752  (test-assert "rationalize (1/3)" (show (rationalize (inexact->exact .3) (/ 1 10))))
    753  (test-assert "rationalize (#i1/3)" (show (rationalize .3 (/ 1 10))))
     752 (test "rationalize (1/3)" 1/3 (rationalize (inexact->exact .3) (/ 1 10)))
     753 (test "rationalize (#i1/3)" #i1/3 (rationalize .3 (/ 1 10)))
    754754)
    755755
Note: See TracChangeset for help on using the changeset viewer.