Changeset 39390 in project


Ignore:
Timestamp:
11/26/20 00:30:25 (5 months ago)
Author:
Kon Lovett
Message:

fix fpprecision-epsilon, add tests

Location:
release/5/fp-utils/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • release/5/fp-utils/trunk/fp-inlines.scm

    r39387 r39390  
    119119(define (fpprecision-factor p #!optional (base 10.0)) (fpexpt base (exact->inexact p)))
    120120
    121 (define (fpprecision-epsilon p #!optional (base 10.0))
    122   (fp/ 1.0 (fpprecision-factor (fpadd1 (exact->inexact p)) base)) )
     121(define (fpprecision-epsilon p #!optional (base 10.0)) (fp/ 1.0 (fpprecision-factor p base)))
    123122
    124123;;
  • release/5/fp-utils/trunk/fp-utils.egg

    r39387 r39390  
    33
    44((synopsis "fp utilities")
    5  (version "4.0.3")
     5 (version "4.0.4")
    66 (category math)
    77 (author "[[kon lovett]]")
  • release/5/fp-utils/trunk/tests/fp-utils-test.scm

    r38875 r39390  
    44(import test)
    55
    6 (test-begin "Fp Utils")
     6(test-begin "FP Utils")
    77
    88;;;
     
    1515(import  (chicken flonum))
    1616
    17 (test-group "Fp Inlines"
     17(test-group "FP Inlines"
    1818
    1919  (test-assert (fpzero? 0.0))
     
    5050;;
    5151
    52 (define-constant 5eps (fp/ 9.0 1e06))
     52(test-group "FP precision"
     53  (test 10.0 (fpprecision-factor 1))
     54  (test 10000000000.0 (fpprecision-factor 10))
     55  (test 15.8489319246111 (fpprecision-factor 1.2))
     56  (test 0.1 (fpprecision-epsilon 1))
     57  (test 0.0000000001 (fpprecision-epsilon 10))
     58  (test 0.0630957344480193 (fpprecision-epsilon 1.2))
     59)
    5360
    54 (test-group "Fp Approximate ="
     61;;
     62
     63(test-group "FP Approximate ="
    5564
    5665  ;sweet, sweet repeating expansion
     
    6069
    6170  ;own epsilon
    62         (test-assert (fp~= 0.123456 0.123457 5eps))
    63         (test-assert (fp~<= 0.123456 0.123457 5eps))
    64         (test-assert (fp~>= 0.123456 0.123457 5eps))
    65         (test-assert (fp~<= 0.123456 0.12346 5eps))
    66         (test-assert (fp~>= 0.123456 0.12344 5eps))
     71        (let ((eps5 (fpprecision-epsilon 5)))
     72    (test-assert (fp~= 0.123456 0.123457 eps5))
     73    (test-assert (fp~<= 0.123456 0.123457 eps5))
     74    (test-assert (fp~>= 0.123456 0.123457 eps5))
     75    (test-assert (fp~<= 0.123456 0.12346 eps5))
     76    (test-assert (fp~>= 0.123456 0.12344 eps5)) )
    6777)
    6878
     
    7181(define-constant 4eps (fp/ 9.0 1e05))
    7282
    73 (test-group "Fp Utils"
     83(test-group "FP Utils"
    7484
    7585        (test 1.0 (fpmodulo 5.0 2.0))
     
    102112;;;
    103113
    104 (test-end "Fp Utils")
     114(test-end "FP Utils")
    105115
    106116(test-exit)
Note: See TracChangeset for help on using the changeset viewer.