tag:blogger.com,1999:blog-36773632.post7323775806842917645..comments2023-12-19T08:40:05.062-05:00Comments on Java Evangelist John Yeary: Floating Point Literal ConversionJohn Yearyhttp://www.blogger.com/profile/00461192445071361043noreply@blogger.comBlogger4125tag:blogger.com,1999:blog-36773632.post-86910885434525679362010-08-18T16:55:49.060-05:002010-08-18T16:55:49.060-05:00I think java does its decimal string to floating-p...I think java does its decimal string to floating-point conversions correctly, according to my testing (unlike <a href="http://www.exploringbinary.com/incorrectly-rounded-conversions-in-visual-c-plus-plus/" rel="nofollow">Visual C++</a> or <a href="http://www.exploringbinary.com/incorrectly-rounded-conversions-in-gcc-and-glibc/" rel="nofollow">GCC/GLIBC</a>). And I don't think it uses David Gay's code either. As for conversion from floating-point to decimal strings, I haven't tested it, so I don't know how well it does.Doctor Binaryhttps://www.blogger.com/profile/12458630612536035194noreply@blogger.comtag:blogger.com,1999:blog-36773632.post-44734725916120034692010-08-18T12:04:15.899-05:002010-08-18T12:04:15.899-05:00Doctor Binary... I have added some additional code...Doctor Binary... I have added some additional code examples, and I uploaded a new version of my NB project.<br /><br />I did note that when I created new values that they added correctly, but this is due to rounding.John Yearyhttps://www.blogger.com/profile/00461192445071361043noreply@blogger.comtag:blogger.com,1999:blog-36773632.post-89208296414538645702010-08-18T08:39:04.533-05:002010-08-18T08:39:04.533-05:00Ahhh...my old arch nemesis the good Doctor Binary....Ahhh...my old arch nemesis the good Doctor Binary. Just kidding. I do like the name. It would be a cool evil villain name. <br /><br />You are correct in that the representation can be done in binary so the results are skewed. <br /><br />I will modify my code and example download to reflect your comments.John Yearyhttps://www.blogger.com/profile/00461192445071361043noreply@blogger.comtag:blogger.com,1999:blog-36773632.post-63471864441033799752010-08-18T07:29:23.533-05:002010-08-18T07:29:23.533-05:00John,
Try something other than 1/8, since that is...John,<br /><br />Try something other than 1/8, since that is exactly representable in binary. Here's your output for 1/3:<br /><br />0.1<br />0.1<br />0.1<br />0.33333334<br />0.33333334<br />0.333<br />0.3333333432674408<br />0.33333334<br /><br />Does that still give you what you expect?Doctor Binaryhttps://www.blogger.com/profile/12458630612536035194noreply@blogger.com