From: Gerry Snyder on 4 Sep 2009 16:29 Bruce wrote: > .... > > why do you think 101 would have an exact representation in binary? Because it is 1100101 ?
From: Donald Arseneau on 4 Sep 2009 16:37 On Sep 4, 11:15 am, Bruce <Bruce_do_not_...(a)example.com> wrote: > why do you think 101 would have an exact representation in binary? Uhhh... because 101 = 1+4+32+64 In fact all integers up to the fp mantissa size are exactly represented as fp numbers. Throw in rational numbers whose fractions bear the pattern of division by two, like 123.625 or even 48.828125 and you have lots more numbers exactly representable. Donald Arseneau
From: Robert Heller on 4 Sep 2009 20:12 At Fri, 04 Sep 2009 13:29:09 -0700 Gerry Snyder <mesmerizerfan(a)gmail.com> wrote: > > Bruce wrote: > > .... > > > > why do you think 101 would have an exact representation in binary? > > Because it is 1100101 ? That is an integer. It is not a floating point binary fraction. > > -- Robert Heller -- 978-544-6933 Deepwoods Software -- Download the Model Railroad System http://www.deepsoft.com/ -- Binaries for Linux and MS-Windows heller(a)deepsoft.com -- http://www.deepsoft.com/ModelRailroadSystem/
From: solar on 5 Sep 2009 00:46 > By the way, you *do* realize that there are much better ways to > generate Pythagorean triples? > > If m and n are relatively prime, m > n, and exactly one of m and > n is even, then > > a = mn, b = m**2 - n**2, c = m**2 + n**2 > > is a primitive Pythagorean triple, and all three sides can be > multiplied by any integer to yield more Pythagorean triples. > No square rooting or other floating point machination needed. > Yes. I just found some code comparing the exectution time of triplets in php, erlang, ruby etc,. and rewrote the same in Tcl. It was only for a comparison. Thanks, --
From: solar on 5 Sep 2009 00:52
> > > if {[expr round($a)] == $a} { > > *I* would suspect this line. > You are comparing with *equality* a > floating point number. That is often bad > news. Remember, the the *computer* is using > finite presision *binary* floating point numbers > the results are not *mathematically* > what you might expect... All it would > take would be some guard bit jitter to > completely ruin your day... Maybe you > want (I'm suspecting that 101.0 is > really 101.00000000001, which is != 101: > if {[expr round($a)] == [expr {int(a)}]} { > Hi, --> if {[expr $a-int($a)] < 0.00001} { incr i } works for atleast N upto 15000, but its extremely slow going. :-( Thanks, -- |