Skip to content

Commit

Permalink
fix addition
Browse files Browse the repository at this point in the history
  • Loading branch information
bhargavkulk committed Sep 22, 2024
1 parent bee14f4 commit b62f93d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
11 changes: 8 additions & 3 deletions src/core/explain.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
(provide explain
actual-errors)

(define 100.l (flonum->logfl 100.0))
(define 32.l (flonum->logfl 32.0))

(define *top-3* (make-parameter #f))

(define MAX-EXP 1023)
Expand Down Expand Up @@ -165,6 +168,8 @@

(define cond-x (abs (/ xfl (+ xfl yfl))))
(define cond-y (abs (/ yfl (+ xfl yfl))))
;(define cond-x.l (logabs (log/ xlog (log+ xlog ylog))))
;(define cond-y.l (logabs (log/ ylog (log+ xlog ylog))))

(define x.eps (+ 127 (bigfloat-exponent (exacts-ref x-ex))))
(define y.eps (+ 127 (bigfloat-exponent (exacts-ref y-ex))))
Expand Down Expand Up @@ -546,13 +551,13 @@
(define explanations-table
(for/list ([(key val) (in-dict expls->points)]
#:unless (zero? (length val)))
(define expr (car key))
(define subexpr (car key))
(define expl (cdr key))
(define err-count (length val))
(define maybe-count (length (hash-ref maybe-expls->points key '())))
(define flow-list (make-flow-table oflow-hash uflow-hash expr expl))
(define flow-list (make-flow-table oflow-hash uflow-hash subexpr expl))

(list (~a (car expr)) (~a expr) (~a expl) err-count maybe-count flow-list)))
(list (~a (car subexpr)) (~a subexpr) (~a expl) err-count maybe-count flow-list)))

(define sorted-explanations-table (take-top-n (sort explanations-table > #:key fourth)))

Expand Down
15 changes: 13 additions & 2 deletions src/core/logspace.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@
(if (log<= A B) A B))

(define (log+ A B)
(define P (logmax A B))
(define Q (logmin A B))
(define P (if (log>= (logabs A) (logabs B)) A B))
(define Q (if (log< (logabs A) (logabs B)) A B))
(match-define (logfl a sa ea) P)
(match-define (logfl b sb eb) Q)
(define x (- eb ea))
Expand Down Expand Up @@ -251,3 +251,14 @@
[(list (or 'PI.f64 'PI.f32 'E.f64 'E.f32)) (flonum->logfl ((impl-info (first expr) 'fl)))]
[(list op args ...) (cons (op->logop op) (map expr->logfl args))]
[sym sym]))

(define x (flonum->logfl 2e+103))
(define 1.l (flonum->logfl 1.0))
(define 2.l (flonum->logfl 2.0))

(define x+1 (log+ x 1.l))
(define 1/x+1 (log/ 1.l x+1))

(define 2/x (log/ 2.l x))

(define res (log- 1/x+1 2/x))

0 comments on commit b62f93d

Please sign in to comment.