8.7 Floating Point different than 8.6.1
Added by Anonymous over 18 years ago
Legacy ID: #3603412 Legacy Poster: Francis Upton (francisu)
I just upgraded to 8.7 from 8.6.1. In my tests some statements that cast some text values to a float (after checking castable as float). Here are the diff results: 1169c1169 < <G3905>22426.051</G3905> --- > <G3905>22426.05</G3905> 1504c1504 < <G5505>279.04998</G5505> --- > <G5505>279.05</G5505> 1512c1512 < <G5514>279.14002</G5514> --- > <G5514>279.14</G5514> 1777c1777 < <G3908>340.07998</G3908> --- > <G3908>340.08</G3908> 1792c1792 < <G3926>340.01502</G3926> --- > <G3926>340.015</G3926> The top value is the actual output, the bottom value is the input text value. Saxon 8.6.1 correctly had both values match. Thanks, Francis
Replies (4)
Please register to reply
RE: 8.7 Floating Point different than 8.6.1 - Added by Anonymous over 18 years ago
Legacy ID: #3603766 Legacy Poster: Michael Kay (mhkay)
Please see http://sourceforge.net/tracker/index.php?func=detail&aid=1439685&group_id=29872&atid=397617 There will always be several different strings that convert to the same floating point number, so when you convert back to a string there can never be a guarantee that you will get the string you started with, though it should always be "equivalent". If you care about precision, I would strongly suggest using double rather than float. Having said that, the new conversion routine introduced in 8.7 has not proved to be a success.
RE: 8.7 Floating Point different than 8.6.1 - Added by Anonymous over 18 years ago
Legacy ID: #3605065 Legacy Poster: Francis Upton (francisu)
Thanks Mike. This use of FP is for simple decimal monetary amounts which don't exceed 2 decimal places, so one hopes that the conversion would be fairly precise. When using relatively small quantities (such as this), is the use of "double" an improvement over "float"? Should I never use float? I took your file and that fixed the problem.
RE: 8.7 Floating Point different than 8.6.1 - Added by Anonymous over 18 years ago
Legacy ID: #3605096 Legacy Poster: Michael Kay (mhkay)
For monetary amounts I would recommend decimal. Float might have enough digits for your numbers, but arithmetic rounding errors accumulate very rapidly in computations, for example if you take an average or a total of a set of numbers.
RE: 8.7 Floating Point different than 8.6.1 - Added by Anonymous over 18 years ago
Legacy ID: #3605103 Legacy Poster: Michael Kay (mhkay)
And yes, my advice is never to use float. I really can't see the need for 32-bit floating point numbers in the 21st century.
Please register to reply