;;;; fp-inlines.scm -*- Scheme -*- ;;;; Kon Lovett, Sep '18 ;;;; Issues ;; ;; - all instances of (fl< -0.0 0.0) found ? (module fp-inlines (;export fpzero? fppositive? fpnegative? fpnon-positive? fpnatural? fpeven? fpodd? fpclosed-right? fpclosed? fpclosed-left? fpclosedr? fpclosedl? fpadd1 fpsub1 fpsqr fpcub fpavg fplog2 fplog10 fpdegree->radian fpradian->degree fpprecision-factor fpprecision-epsilon fp% fpsimple-interest fpcompound-interest) (import scheme) (import (chicken base)) (import (chicken type)) (import (chicken flonum)) ;;;(mathh/mathh-constants) (define-constant FPLN2 0.6931471805599453094172321214581765680755) ;ln(2) (define-constant FPLN10 2.3025850929940456840179914546843642076011) ;ln(10) ; atan(1) / 45 (define-constant FPDEG2RAD 0.0174532925199432957692369076848861271344) ;pi/180 ;;; ;; (: fpzero? (float -> boolean)) (: fppositive? (float -> boolean)) (: fpnatural? (float -> boolean)) (: fpnegative? (float -> boolean)) (: fpnon-positive? (float -> boolean)) (: fpeven? (float -> boolean)) (: fpodd? (float -> boolean)) (: fpclosed-right? (float float float -> boolean)) (: fpclosed? (float float float -> boolean)) (: fpclosed-left? (float float float -> boolean)) (: fpadd1 (float -> float)) (: fpsub1 (float -> float)) (: fpsqr (float -> float)) (: fpcub (float -> float)) (: fplog2 (float -> float)) (: fplog10 (float -> float)) (: fpdegree->radian (float -> float)) (: fpradian->degree (float -> float)) (: fpprecision-factor ((or float fixnum) #!optional float -> float)) (: fpprecision-epsilon ((or float fixnum) #!optional float -> float)) (: fp% (float (or float fixnum) -> float)) (: fpavg (float float -> float)) (: fpsimple-interest (float float #!optional float -> float)) (: fpcompound-interest (float float float #!optional float -> float)) ;; (define (fpzero? n) (or (fp= 0.0 n) (fp= -0.0 n))) (define (fppositive? n) (fp< 0.0 n)) (define (fpnatural? n) (fp<= 0.0 n)) (define (fpnegative? n) (fp> 0.0 n)) (define (fpnon-positive? n) (fp>= 0.0 n)) ;; (define (fpeven? n) (fpinteger? (fp/ n 2.0))) (define (fpodd? n) (not (fpeven? n))) ;; (define (fpclosed-right? l x h) (and (fp< l x) (fp<= x h))) (define (fpclosed? l x h) (and (fp<= l x) (fp<= x h))) (define (fpclosed-left? l x h) (and (fp<= l x) (fp< x h))) ;inline, remember (define (fpclosedr? l x h) (fpclosed-right? l x h)) (define (fpclosedl? l x h) (fpclosed-left? l x h)) ;; (define (fpadd1 n) (fp+ n 1.0)) (define (fpsub1 n) (fp- n 1.0)) ;; (define (fpsqr n) (fp* n n)) (define (fpcub n) (fp* n (fp* n n))) (define (fpavg a b) (fp/ (fp+ a b) 2.0)) ;; (define (fplog2 x) (fp/ (fplog x) FPLN2)) (define (fplog10 x) (fp/ (fplog x) FPLN10)) ;; (define (fpdegree->radian deg) (fp* deg FPDEG2RAD)) (define (fpradian->degree rad) (fp/ rad FPDEG2RAD)) ;; ;NOTE not actually inline ? (define (fpprecision-factor p #!optional (base 10.0)) (fpexpt base (exact->inexact p))) (define (fpprecision-epsilon p #!optional (base 10.0)) (fp/ 1.0 (fpprecision-factor p base))) ;; (define (fp% n p) (fp* n (fp* (exact->inexact p) .01))) ;; ;rate is per time period units, freq & perd must be in same time units ; (define (fpsimple-interest rate time #!optional (prin 1.0)) (fp* prin (fp+ 1.0 (fp* rate time))) ) (define (fpcompound-interest rate freq time #!optional (prin 1.0)) (fp* prin (fpexpt (fp+ 1.0 (fp/ rate freq)) (fp* freq time))) ) ) ;fp-inlines