Changeset 37874 in project


Ignore:
Timestamp:
09/02/19 01:56:29 (3 weeks ago)
Author:
Kon Lovett
Message:

add kahan summation

File:
1 edited

Legend:

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

    r36955 r37874  
    1010
    1111(;export
     12  ;
     13  fpsummation
    1214  ;
    1315  fprandom
     
    3436  fx-utils
    3537  fp-inlines)
     38
     39;;;
     40
     41;;
     42
     43(: fpsum ((list-of float) --> float))
     44;
     45(define (fpsummation ls)
     46  (if (null? ls)
     47    0.0
     48    ;Kahan Summation Formula
     49    (let sum ((s (car ls)) (c 0.0) (ls (cdr ls)))
     50      (if (null? ls)
     51        s
     52        (let* (
     53          (y (fp- (car ls) c))
     54          (t (fp+ s y)) )
     55          (sum t (fp- (fp- t s) y) (cdr ls)) ) ) ) ) )
    3656
    3757;;;
Note: See TracChangeset for help on using the changeset viewer.