Changeset 39387 in project


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

fix fp*-with-precision p argument type handling, type is iterface

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

Legend:

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

    r38251 r39387  
    1818  fplog2 fplog10
    1919  fpdegree->radian fpradian->degree
    20   fpprecision-factor)
     20  fpprecision-factor fpprecision-epsilon)
    2121
    2222(import scheme)
     
    3838
    3939(: fpzero? (float --> boolean))
    40 ;
     40(: fppositive? (float --> boolean))
     41(: fpnatural? (float --> boolean))
     42(: fpnegative? (float --> boolean))
     43(: fpnon-positive? (float --> boolean))
     44(: fpeven? (float --> boolean))
     45(: fpodd? (float --> boolean))
     46(: fpclosed-right? (float float float --> boolean))
     47(: fpclosed? (float float float --> boolean))
     48(: fpclosed-left? (float float float --> boolean))
     49(: fpadd1 (float --> float))
     50(: fpsub1 (float --> float))
     51(: fplog2 (float --> float))
     52(: fplog10 (float --> float))
     53(: fpdegree->radian (float --> float))
     54(: fpradian->degree (float --> float))
     55(: fpprecision-factor ((or float fixnum) #!optional float --> float))
     56(: fpprecision-epsilon ((or float fixnum) #!optional float --> float))
     57(: fp% (float float --> float))
     58
     59;;
     60
    4161(define (fpzero? n) (or (fp= 0.0 n) (fp= -0.0 n)))
    4262
    43 (: fppositive? (float --> boolean))
    44 ;
    4563(define (fppositive? n) (fp< 0.0 n))
    4664
    47 (: fpnatural? (float --> boolean))
    48 ;
    4965(define (fpnatural? n) (fp<= 0.0 n))
    5066
    51 (: fpnegative? (float --> boolean))
    52 ;
    5367(define (fpnegative? n) (fp> 0.0 n))
    5468
    55 (: fpnon-positive? (float --> boolean))
    56 ;
    5769(define (fpnon-positive? n) (fp>= 0.0 n))
    5870
    5971;;
    6072
    61 (: fpeven? (float --> boolean))
    62 ;
    6373(define (fpeven? n) (fpinteger? (fp/ n 2.0)))
    6474
    65 (: fpodd? (float --> boolean))
    66 ;
    6775(define (fpodd? n) (not (fpeven? n)))
    6876
    6977;;
    7078
    71 (: fpclosed-right? (float float float --> boolean))
    72 ;
    7379(define (fpclosed-right? l x h) (and (fp< l x) (fp<= x h)))
    7480
    75 (: fpclosed? (float float float --> boolean))
    76 ;
    7781(define (fpclosed? l x h) (and (fp<= l x) (fp<= x h)))
    7882
    79 (: fpclosed-left? (float float float --> boolean))
    80 ;
    8183(define (fpclosed-left? l x h) (and (fp<= l x) (fp< x h)))
    8284
     
    8789;;
    8890
    89 (: fpadd1 (float --> float))
    90 ;
    9191(define (fpadd1 n) (fp+ n 1.0))
    9292
    93 (: fpsub1 (float --> float))
    94 ;
    9593(define (fpsub1 n) (fp- n 1.0))
    9694
     
    107105;;
    108106
    109 (: fplog2 (float --> float))
    110 ;
    111107(define (fplog2 x) (fp/ (fplog x) 0.6931471805599453094172321214581765680755))
    112108
    113 (: fplog10 (float --> float))
    114 ;
    115109(define (fplog10 x) (fp/ (fplog x) 2.3025850929940456840179914546843642076011))
    116110
    117111;;
    118112
    119 (: fpdegree->radian (float --> float))
    120 ;
    121113(define (fpdegree->radian deg) (fp* deg 0.0174532925199432957692369076848861271344))
    122114
    123 (: fpradian->degree (float --> float))
    124 ;
    125115(define (fpradian->degree rad) (fp/ rad 0.0174532925199432957692369076848861271344))
    126116
    127117;;
    128118
    129 (: fpprecision-factor ((or float fixnum) #!optional float --> float))
    130 ;
    131119(define (fpprecision-factor p #!optional (base 10.0)) (fpexpt base (exact->inexact p)))
    132120
    133 #|
     121(define (fpprecision-epsilon p #!optional (base 10.0))
     122  (fp/ 1.0 (fpprecision-factor (fpadd1 (exact->inexact p)) base)) )
     123
    134124;;
    135125
    136 (: fp% (float float --> float))
    137 ;
    138 (define (fp% n p) (fp/ (fp* 100.0 n) p))
    139 |#
     126(define (fp% n p) (fp/ (fp* 100.0 n) (exact->inexact p)))
    140127
    141128) ;fp-inlines
  • release/5/fp-utils/trunk/fp-utils.egg

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

    r38251 r39387  
    3939;;;
    4040
    41 ;;
    42 
    4341(: fpsum ((list-of float) --> float))
    44 ;
     42(: C_fmod (float float --> float))
     43(: C_remainder (float float --> float))
     44(: fpmodulo (float float --> float))
     45(: fpquotient (float float --> float))
     46(: fpremainder (float float --> float))
     47(: fptruncate-with-precision (float #!optional float --> float))
     48(: fpround-with-precision (float #!optional float --> float))
     49(: fpceiling-with-precision (float #!optional float --> float))
     50(: fpfloor-with-precision (float #!optional float --> float))
     51(: fpdistance (float float float float --> float))
     52(: fpdistance* (float float float float --> float))
     53(: fpquo-and-rem (float float --> float float))
     54(: fpmax-and-min (float #!rest float --> float float))
     55(: fprandom (#!optional (or float fixnum) (or float fixnum) -> float))
     56(: fp~= (float float #!optional float --> boolean))
     57(: fp~<= (float float #!optional float --> boolean))
     58(: fp~>= (float float #!optional float --> boolean))
     59
     60;;
     61
    4562(define (fpsummation ls)
    4663  (if (null? ls)
     
    5774;;;
    5875
    59 (: C_fmod (float float --> float))
    60 ;
    6176(define C_fmod (foreign-lambda double "fmod" double double))
    6277
    63 (: C_remainder (float float --> float))
    64 ;
    6578(define C_remainder (foreign-lambda double "remainder" double double))
    6679
    6780;;
    6881
    69 (: fpmodulo (float float --> float))
    70 ;
    7182(define (fpmodulo x y) (fptruncate (C_fmod x y)))
    7283
    73 (: fpquotient (float float --> float))
    74 ;
    7584(define (fpquotient x y) (fptruncate (fp/ x y)))
    7685
    77 (: fpremainder (float float --> float))
    78 ;
    7986(define (fpremainder x y) (fptruncate (C_remainder x y)))
    8087
     
    8895    ((make-unary-with-precision ?op)
    8996      (lambda (n #!optional (p PRECISION-DEFAULT))
    90         (if (fpzero? p)
     97        (if (fpzero? (exact->inexact p))
    9198          (?op n)
    9299          (let ((pf (fpprecision-factor p)))
     
    95102;;
    96103
    97 (: fptruncate-with-precision (float #!optional float --> float))
    98 ;
    99104(define fptruncate-with-precision (make-unary-with-precision fptruncate))
    100105
    101 (: fpround-with-precision (float #!optional float --> float))
    102 ;
    103106(define fpround-with-precision (make-unary-with-precision fpround))
    104107
    105 (: fpceiling-with-precision (float #!optional float --> float))
    106 ;
    107108(define fpceiling-with-precision (make-unary-with-precision fpceiling))
    108109
    109 (: fpfloor-with-precision (float #!optional float --> float))
    110 ;
    111110(define fpfloor-with-precision (make-unary-with-precision fpfloor))
    112111
    113112;;
    114113
    115 (: fpdistance (float float float float --> float))
    116 ;
    117114(define (fpdistance x1 y1 x2 y2) (fpsqrt (fpdistance* x1 y1 x2 y2)))
    118115
    119 (: fpdistance* (float float float float --> float))
    120 ;
    121116(define (fpdistance* x1 y1 x2 y2) (fp+ (fpsqr (fp- x1 x2)) (fpsqr (fp- y1 y2))))
    122117
    123118;;
    124119
    125 (: fpquo-and-rem (float float --> float float))
    126 ;
    127120(define (fpquo-and-rem fpn fpd) (values (fpquotient fpn fpd) (fpremainder fpn fpd)))
    128121
    129122;;
    130123
    131 (: fpmax-and-min (float #!rest float --> float float))
    132 ;
    133124(define (fpmax-and-min fp . fps)
    134125  (let loop ((fps fps) (mx fp) (mn fp))
     
    140131;;
    141132
    142 (: fprandom (#!optional (or float fixnum) (or float fixnum) -> float))
    143 ;
    144133(define-inline (*fpinv x) (if (fpzero? x) 0.0 (fp/ 1.0 x)))
    145134(define-inline (*fpinvfx x) (inexact->exact (*fpinv x)))
     
    163152;;
    164153
    165 (: fp~= (float float #!optional float --> boolean))
    166 ;
    167154(define (fp~= x y #!optional (eps flonum-epsilon))
    168155  ;NOTE minimum/maximum-flonum is smallest/largest positive normal flonum
     
    182169          (fp< (fpabs (fp/ d y)) eps) ) ) ) ) )
    183170
    184 (: fp~<= (float float #!optional float --> boolean))
    185 ;
    186171(define (fp~<= x y #!optional (eps flonum-epsilon)) (or (fp< x y) (fp~= x y eps)))
    187172
    188 (: fp~>= (float float #!optional float --> boolean))
    189 ;
    190173(define (fp~>= x y #!optional (eps flonum-epsilon)) (or (fp> x y) (fp~= x y eps)))
    191174
    192175#|
    193 ;;
    194 
    195 (: fp% (float number --> float))
    196 ;
    197 (define (fp% n p)
    198   (fp* (fp* (exact->inexact p) 0.01) n) )
    199 
    200176;;
    201177
Note: See TracChangeset for help on using the changeset viewer.