Changeset 15571 in project


Ignore:
Timestamp:
08/26/09 05:57:41 (10 years ago)
Author:
Kon Lovett
Message:

Fix for 1.0+1i not treated as a rectnum or compnum [Bug noted by John Cowan] Added 'cintnum?' & 'cplxnum?'.

Location:
release/4/numbers
Files:
3 edited

Legend:

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

    r11917 r15571  
    5353       number? complex? real? rational? integer?
    5454       make-rectangular make-polar real-part imag-part magnitude angle
    55        bignum? ratnum? cflonum? rectnum? compnum?
     55       bignum? ratnum? cflonum? rectnum? compnum? cintnum? cplxnum?
    5656       numbers:+ numbers:- numbers:> numbers:< numbers:=
    5757       numbers:>= numbers:<=)
     
    770770  (switchq (%check-number x)
    771771    (FIX #t)
     772    (FLO (%flo-integer? x))
    772773    (BIG #t)
    773     (FLO (%flo-integer? x))
    774774    (else #f) ) )
    775775
     
    14071407;;; Non-standard type procedures
    14081408
    1409 (define (bignum? x)
     1409(define (bignum? x)     ; big number
    14101410  (switchq (%check-number x)
    14111411    (BIG #t)
    14121412    (else #f) ) )
    14131413
    1414 (define (ratnum? x)
     1414(define (ratnum? x)     ; ratio number
    14151415  (switchq (%check-number x)
    14161416    (RAT #t)
    14171417    (else #f) ) )
    14181418
    1419 (define (cflonum? x)
     1419(define (cplxnum? x)    ; complex number
     1420  (switchq (%check-number x)
     1421    (COMP #t)
     1422    (else #f) ) )
     1423
     1424(define (rectnum? x)    ; "exact" complex number
     1425  (define (%rect-part? x)
     1426    #;(assert (and (not (eq? COMP (%check-number x))) (not (eq? NONE (%check-number x)))))
     1427    (switchq (%check-number x)
     1428      (FLO (%flo-integer? x))
     1429      (else #t) ) )
     1430  (switchq (%check-number x)
     1431    (COMP (and (%rect-part? (complex-real x)) (%rect-part? (complex-imag x))))
     1432    (else #f) ) )
     1433
     1434(define (compnum? x)    ; inexact complex number
     1435  (switchq (%check-number x)
     1436    (COMP (and (%inexact? (complex-real x)) (%inexact? (complex-imag x))))
     1437    (else #f) ) )
     1438
     1439(define (cintnum? x)    ; integer number
     1440  (switchq (%check-number x)
     1441    (FIX #t)
     1442    (BIG #t)
     1443    (FLO (%flo-integer? x))
     1444    (COMP (and (%integer? (complex-real x)) (%integer? (complex-imag x))))
     1445    (else #f) ) )
     1446
     1447(define (cflonum? x)    ; floatingpoint number
    14201448  (switchq (%check-number x)
    14211449    (FLO #t)
    1422     (COMP (%inexact? x))
     1450    (COMP (and (%flonum? (complex-real x)) (%flonum? (complex-imag x))))
    14231451    (else #f) ) )
    14241452
    1425 (define (rectnum? x)
    1426   (switchq (%check-number x)
    1427     (COMP (%exact? x))
    1428     (else #f) ) )
    1429 
    1430 (define (compnum? x)
    1431   (switchq (%check-number x)
    1432     (COMP (%inexact? x))
    1433     (else #f) ) )
    1434 
    14351453;;; What we provide
    14361454
  • release/4/numbers/numbers.setup

    r11101 r15571  
    1212  'numbers
    1313  '("numbers.so" "numbers-static.o" "numbers.import.so")
    14   `((version "1.807")
     14  `((version "1.808")
    1515    (static "numbers-static.o")
    1616    (static-options "-lgmp")))
  • release/4/numbers/tests/numbers-test.scm

    r11101 r15571  
    445445
    446446)
     447
     448(testeez
     449 "non-standard type procedures"
     450
     451 (test/eq "bignum" #t (bignum? b1))
     452
     453 (test/eq "ratnum" #t (ratnum? r1))
     454
     455 (test/eq "cplxnum: compintintnum" #t (cplxnum? c1))
     456 (test/eq "cplxnum: compintflointnum" #t (cplxnum? 1.0+1i))
     457 (test/eq "cplxnum: compflointnum" #t (cplxnum? c2))
     458 (test/eq "cplxnum: compfloflonum" #t (cplxnum? 3.4-4.3i))
     459 (test/eq "not cplxnum: fixnum" #f (cplxnum? 1))
     460
     461 (test/eq "rectnum: compintintnum" #t (rectnum? c1))
     462 (test/eq "rectnum: compintflointnum" #t (rectnum? 1.0+1i))
     463 (test/eq "not rectnum: compflointum" #f (rectnum? c2))
     464
     465 (test/eq "compnum: compfloflonum" #t (compnum? 3.4-4.3i))
     466 (test/eq "not compnum: compflointnum" #f (compnum? 1.0+1i))
     467 (test/eq "not compnum: compintintnum" #f (compnum? c1))
     468
     469 (test/eq "cintnum: intflonum" #t (cintnum? 1.0))
     470 (test/eq "cintnum: fixnum" #t (cintnum? 3))
     471 (test/eq "cintnum: bignum" #t (cintnum? b1))
     472 (test/eq "cintnum: compintintnum" #t (cintnum? c1))
     473
     474 (test/eq "cflonum: intflonum" #t (cflonum? 1.0))
     475 (test/eq "cflonum: flonum" #t (cflonum? 3.4))
     476 (test/eq "cflonum: compfloflonum" #t (cflonum? 3.4-4.3i))
     477 (test/eq "cflonum: compfloflonum" #f (cflonum? c2))
     478
     479)
Note: See TracChangeset for help on using the changeset viewer.