[ prog / sol / mona ]

prog


Challenge^2: Floating Point without Errors

5 2020-10-16 17:37

Task 3 is also easy:

(define (task-3 a b)
  (+ (* (+ 333 3/4) (expt b 6))
     (* (expt a 2) (- (* 11 (expt a 2) (expt b 2))
                      (expt b 6)
                      (* 121 (expt b 4))
                      2))
     (* (+ 5 1/2) (expt b 8))
     (/ a (* 2 b))))

(display "Task 3:\n")
(let ((result (task-3 77617 33096)))
  (display `(,result (approx: ,(exact->inexact result)))))
(newline)

>>3
Irrational numbers have an infinite number of non-repeating decimals, the only exact way to represent them is symbolic:

(define (task-2 years)
  (let loop ((n 1) (e 1) (m 1))
    (if (<= n years)
        (loop (+ n 1) (* e n) (+ (* m n) 1))
        `(- (* ,e e) ,m))))

(display "Task 2:\n")
(display (task-2 25))
(newline)
59


VIP:

do not edit these