![]() |
| ||
| iomanip, setprecision - inprecise? Learning about all functions in <iomanip> and was testing out setprecision() and found that something weird is going on...? I did try to do a search on setprecision() limitatations or similar keywords but can't seem to find the right site... can someone please tell me what's going on? double a = 0.1, b = 0.2, c = 0.3, d = 0.4, e = 0.5;outputs: 0.10000000000000001000 |
| ||
| Re: iomanip, setprecision - inprecise? setprecision does nothting but increase decimal places at right. For example setprecision(2) for 2 will give 2.00 and setprecision(5) will give 2.00000 Which compiler do you use. |
| ||
| Re: iomanip, setprecision - inprecise? I compiled in cygwin so g++. I didn't mean anything wrong with setprecision() but discovered it while playing with it but why ain't the numbers precise? Isn't that very bad for scientific calculations? |
| ||
| Re: iomanip, setprecision - inprecise? Floating point numbers are not stored precisely in memory. They are usually stored according to the IEEE 754 standard. If you want exact precision, you need to use a 3rd party library or write your own. For most calculations, however, the small degree of error is acceptable. |
| ||
| Re: iomanip, setprecision - inprecise? I see, so for those scientic calculators in C++ they use other libraries for better precisions instead of the standard one. Got it, thanks. |
| All times are GMT -4. The time now is 7:00 pm. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC