Here's why in Javascript: Welcome to Console for JScript v5.7.5730, Windows Script Host v5.6. (C) Copyright 2000-2004 Oleg Kobchenko. No warranties extended.
7 - 100*0.07 -8.881784197001252e-16 (0.07).toString(2) 0.000100011110101110000101000111101011100001010001111011 (100*0.07).toString(2) 111.00000000000000000000000000000000000000000000000001 (7).toString(2) 111 (7 - 100*0.07).toString(2) -0.00000000000000000000000000000000000000000000000001 (7 - 100*0.07).toString(2).length 53 Math.pow(2,50) 1125899906842624 1/Math.pow(2,50) 8.881784197001252e-16 --- Roger Hui <[EMAIL PROTECTED]> wrote: > > ps: I've never understood people who prefer fast answers to > > correct ones. > > 7 - 100 * 7r100 > 0 > 7 - 100 * 0.07 > _8.88178e_16 > > The first is slow but "correct". The second is fast but "not correct". > But there are any number of situations where I would prefer the > second approach. (The first uses exact rational arithmetic; > the second uses 64-bit floating point.) > > > > ----- Original Message ----- > From: Robert Bernecky <[EMAIL PROTECTED]> > Date: Friday, October 5, 2007 9:43 > Subject: Re: [Jgeneral] 9!:10 and linear display > To: General forum <[email protected]> > > > This topic may have beaten to death by now, but a few comments: > > > > 1. Guy Steele and Jon White wrote > > "How to print floating-point numbers accurately" > > in 1990 (SIGPLAN PLDI 1990). This paper set the > > stage for > > proper formatting of floating-point numbers. > > > > 2. Doug Forkes analyzed their approach (which was available > > by rumor quite a bit earlier, new of which had been > > brought to > > us at I.P. Sharp by LMB (Larry M. Breed)), and > > rewrote the > > floating-point > > formatter for SHARP APL. Doug's approach was, if I > > recall > > correctly, quite a bit faster than the Steele/White > > approach. I think he did something along the lines > > of what Burger and > > Dybvig, below, did, but would welcome word from > > Doug on this. > > > > Doug's implementation had one notable effect: > > The bug reports > > that we'd get about once a month about bad > > formatting of 0.07, > > which would print as something like > > 0.070000000000001 with the > > old formatter, but which printed as 0.07 with the > > new one, simply > > stopped coming in. > > > > 3. Robert G. Burger and R. Kent Dybvig. Printing floating-point > > numbersquickly and accurately. In Proceedings of the ACM SIGPLAN > > '96 Conference > > on Programming Language Design and Implementation, pages 108--116. > > http://citeseer.ist.psu.edu/28233.html > > This paper presents the same approach to numeric formatting, but their > > algorithm is substantially faster than that of Steele and White. > > > > The change is NOT, in my opinion, cosmetic, as it also corrects > > a number > > of other evils, such as racheting, which can occur when you repeatedly > > format and unformat a number, and it slowly increases or > > decreases in > > value. > > Both papers are worthy of reading, as they make it quite evident that > > correct formatting is (a) not costly and is (b) not merely cosmetic. > > > > 4. I have heard rumors that the new IEEE floating-point standard will > > contain formatting rules that conform to the above > > papers. That means that new FPU boxes will likely > > include formatter and > > unformatter instructions, at which point any > > complaints about > > "large price to pay" will certainly go away. > > > > Bob > > > > ps: I've never understood people who prefer fast answers to > > correct ones. > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm > ____________________________________________________________________________________ Be a better Globetrotter. Get better travel answers from someone who knows. Yahoo! Answers - Check it out. http://answers.yahoo.com/dir/?link=list&sid=396545469 ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
