From: Rick.Regan on 28 Jun 2010 06:14 { Please use a proper style of quoting. With the style used here, it is difficult for the readers to find out which article your reply is made to and which context it is referring to. The canonical style goes like this: <example> previous author wrote: > the previous content what you add to it > the previous content what you add to it </example> Note that the previous content is marked by a quoting mark (">") and your content follows after the quoted content. -mod } When I convert "0.0003" and "3.e-4" in VC++ they are the same value: 0x1.3a92a30553261p-12. George Neuner wrote: Yes, I am aware of this. However, conversion of "0.0003" and "3. 28-Jun-10 Yes, I am aware of this. However, conversion of "0.0003" and "3.e-4" should produce the same bits. In VC++, the two conversions produce different results. This (IMO and that of many others) is wrong. George Previous Posts In This Thread: Submitted via EggHeadCafe - Software Developer Portal of Choice Composite UI Pattern And Enterprise Settings http://www.eggheadcafe.com/tutorials/aspnet/ff14a008-2af9-4f9d-a09d-1af670466a80/aspnet-gridview-select-row-and-display-item-detail.aspx -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: George Neuner on 29 Jun 2010 16:54 On Mon, 28 Jun 2010 15:14:45 CST, Rick.Regan(a)giganews.com wrote: >When I convert "0.0003" and "3.e-4" in VC++ they are the same value: Which version are you using and how are you doing it? VC2002,03,05 and 08 all fail to produce equivalent values when using stream input, but scanf() produces equivalent values in all of them. It doesn't matter whether the text is parsed from a file or from a string. int main( void ) { double v1, v2, v3, v4; std::cin >> v1 >> v2; std::cout << std::endl << v1 << std::string((v1 != v2) ? " != " : " == ") << v2 << std::endl; scanf( "%lf %lf", &v3, &v4 ); std::cout << std::endl << v3 << std::string((v3 != v4) ? " != " : " == ") << v4 << std::endl; return 0; } with input: 3e-4 0.0003 3e-4 0.0003 produces output: 0.0003 != 0.0003 0.0003 == 0.0003 With the understanding that VC's debugger doesn't necessarily show all the digits of a double, the values are: v1 = 0.00029999999999999997 v2 = 0.00030000000000000003 v3 = 0.00029999999999999997 v4 = 0.00029999999999999997 >0x1.3a92a30553261p-12. What the heck is that? George -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
|
Pages: 1 Prev: Solid C++ by example Next: best way to disambiguate an overloaded function. |