Re: When arithmetic on a computer bite back

2012-06-03 Thread Tassilo Horn
Mark Engelberg writes: > 1.4411518807585587E17 ends in 0, Oh, my counting was bad yesterday. > and therefore when you divide by 2, it should end in 5. It's not a > power of 2, it is a merely an inexact approximation of one. Yes. Bye, Tassilo -- You received this message because you are sub

Re: When arithmetic on a computer bite back

2012-06-02 Thread Mark Engelberg
1.4411518807585587E17 ends in 0, and therefore when you divide by 2, it should end in 5. It's not a power of 2, it is a merely an inexact approximation of one. On Sat, Jun 2, 2012 at 2:31 AM, Tassilo Horn wrote: > Yes, you did. How can a power of two divided by two be *odd* (well, > except for

Re: When arithmetic on a computer bite back

2012-06-02 Thread Tassilo Horn
kawas writes: > I've checked with a python repl, the correct value seems to be the one > using BigDecs > from decimal import * Decimal('1.4411518807585587E17') / Decimal(2) > Decimal('72057594037927935') > > I've submitted a bug and commented on it about BigDecimal constructors > but I

Re: When arithmetic on a computer bite back

2012-06-01 Thread kawas
I've checked with a python repl, the correct value seems to be the one using BigDecs >>> from decimal import * >>> Decimal('1.4411518807585587E17') / Decimal(2) Decimal('72057594037927935') I've submitted a bug and commented on it about BigDecimal constructors but I may have made a mistake about

Re: When arithmetic on a computer bite back

2012-06-01 Thread Tassilo Horn
kawas writes: Hi Laurent, > (defn prime-factors [n] > (loop [f 2 n n res []] > (cond > (<= n 1) res > (zero? (rem n f)) (recur f (quot n f) (conj res f)) > :else (recur (inc f) n res > > Problem 1 (solved): If you use (= n 1) in the first cond clause, the > function m

When arithmetic on a computer bite back

2012-06-01 Thread kawas
Hi, Can someone explain to me the behavior of this function when applied to different kind of numbers. (defn prime-factors [n] (loop [f 2 n n res []] (cond (<= n 1) res (zero? (rem n f)) (recur f (quot n f) (conj res f)) :else (recur (inc f) n res Problem 1 (solved):