From: Chaim T. - I. <Ch...@gi...> - 2004-09-22 10:28:10
|
Yes I used the delta and it worked. thanks. Chaim Turkel -----Original Message----- From: Martin Larsson [mailto:mar...@gm...] Sent: Wednesday, September 22, 2004 11:45 AM To: dun...@li... Subject: Re: [DUnit-interest] Double On Wed, 22 Sep 2004 10:34:40 +0200, Chaim Turkel - Israel <ch...@gi...> wrote: Please trim your ridiculusly large sig. Four lines should be enough. If you really really need the world to know your phone number, put it on a web-site, and put a link in your sig. And please please please start a new thread for new questions. Your answer looks like a reply to an existing thread. Don't reply and change the title, start a new message. Ok? Now ... back to your question. > dTest : Double; > dTest := 3.4; > CheckEquals(3.4, dTest); > > the test fails? Most numbers can't be represented on a computer. So we do an approximation. Roughly, each bit represents 1/2^n. So 0.5 is 1, 0.25 is 01, 0.75 is 11, 0.675 is 101 and so on. You can see this nicely here: dTest := 0; for i := 1 to 10 do dTest := dTest + 0.1; if dTest <> 1 then ShowMessage('wow...' + FloatToStr(dTest - 1)); CheckEquals takes to parameters of type extended. You're passing in a double. The approximation to 3.4 is different in extended and double since extended has more bits to use. So the comparison fails. If you change the type of dTest to extended, the comparison holds. If you add a third 'delta' parameter (of ... say 1E-10), the comparison holds. Did that help? M. ------------------------------------------------------- This SF.Net email is sponsored by: YOU BE THE JUDGE. Be one of 170 Project Admins to receive an Apple iPod Mini FREE for your judgement on who ports your project to Linux PPC the best. Sponsored by IBM. Deadline: Sept. 24. Go here: http://sf.net/ppc_contest.php _______________________________________________ Dunit-interest mailing list Dun...@li... https://lists.sourceforge.net/lists/listinfo/dunit-interest |