|
51 | 51 | %
|
52 | 52 | \begin{sloppypar}%
|
53 | 53 | Finally, the \pgls{signBit} in the floating point number dataformat indicates whether the number is positive or negative.
|
54 |
| -Together, this allows us to represent numbers from $2.225\decSep073\decSep858\decSep507\decSep201\decSep4*10^{-308}$ to $1.797\decSep693\decSep134\decSep8623\decSep157*10^{308}$ with a resolution of approximately 15~digits. |
| 54 | +Together, this allows us to represent numbers from $2.225\decSep073\decSep858\decSep507\decSep201\decSep4*10^{-308}$ to $1.797\decSep693\decSep134\decSep8623\decSep157*10^{308}$\pythonIdx{1.7976931348623157e+308}\pythonIdx{float!largest} with a resolution of approximately 15~digits. |
55 | 55 | Of course, the same range also applies to negative numbers and $0$~can be represented as well.
|
56 | 56 | Indeed, there are even special floating point values for infinity and errors.
|
57 | 57 | But more about this later.%
|
|
301 | 301 | Thus \pythonil{9e-324} and \pythonil{1e-323} map to the same \pythonilIdx{float}.
|
302 | 302 | Converting this \pythonilIdx{float} to text yields \pythonil{'1e-323'}.
|
303 | 303 | The same happens for \pythonil{8e-324}, which also maps to \pythonil{1e-323}.
|
304 |
| -\pythonil{7e-324}, however, is the same as \pythonilIdx{5e-324}. |
305 |
| -Matter of fact, \pythonil{6e-324}, \pythonil{5e-324}, \pythonil{4e-324}, and \pythonil{3e-324} all map to this same \pythonilIdx{float}. |
| 304 | +\pythonil{7e-324}, however, is the same as \pythonilIdx{5e-324}\pythonIdx{float!smallest}. |
| 305 | +Matter of fact, \pythonil{6e-324}, \pythonilIdx{5e-324}, \pythonil{4e-324}, and \pythonil{3e-324} all map to this same \pythonilIdx{float}\pythonIdx{float!smallest}. |
306 | 306 |
|
307 | 307 | It turns out that this number is already the smallest \pythonilIdx{float} that can be represented:
|
308 | 308 | \pythonil{2e-324} simply becomes \pythonilIdx{0.0}.
|
|
321 | 321 |
|
322 | 322 | But what happens to numbers that are too big for the available range?
|
323 | 323 | Again, according to the nice documentation of \pgls{Java}, the maximum 64~bit double precision floating point number value is~$(2-2^{-52})*2^{1023}\approx1.797\decSep693\decSep134\decSep862\decSep315\decSep708\dots*10^{308}$.
|
324 |
| -We can enter this value as \pythonilIdx{1.7976931348623157e+308} and it indeed prints correctly in \cref{fig:floatMathInConsoleInf}. |
325 |
| -If we step it up a little bit and enter \pythonil{1.7976931348623158e+308}, due to the limited precision, we again get \pythonil{1.7976931348623157e+308}. |
| 324 | +We can enter this value as \pythonilIdx{1.7976931348623157e+308}\pythonIdx{float!largest} and it indeed prints correctly in \cref{fig:floatMathInConsoleInf}. |
| 325 | +If we step it up a little bit and enter \pythonil{1.7976931348623158e+308}, due to the limited precision, we again get \pythonilIdx{1.7976931348623157e+308}\pythonIdx{float!largest}. |
326 | 326 | However, if we try entering \pythonil{1.7976931348623159e+308} into the \python\ console, something strange happens:
|
327 | 327 | The output is \pythonilIdx{inf}.
|
328 | 328 | \pythonil{-1.7976931348623159e+308} gives us \pythonilIdx{-inf}.
|
329 | 329 | Multiplying this value by two, i.e., computing \pythonil{-1.7976931348623157e+308 * 2}, still yields \pythonil{-inf}.
|
330 | 330 | Intuitively, based on its name, one would assume that \pythonilIdx{inf} stands for \inQuotes{infinity} or~$\infty$.
|
331 | 331 | However, it \emph{actually} means \emph{too big to represent as \pythonilIdx{float} or~$\infty$}.
|
332 | 332 | If we enter numbers that are too big or exceed the valid range of \pythonilIdx{float} by multiplication, addition, subtraction, or division, we simply get~\pythonilIdx{inf}.
|
333 |
| -This does not actually mean \inQuotes{mathematical infinity,} because, while \pythonil{-1.7976931348623159e+308} is very big, it is not infinitely big. |
| 333 | +This does not actually mean \inQuotes{mathematical infinity,} because, while \pythonil{-1.7976931348623159e+308}\pythonIdx{float!largest} is very big, it is not infinitely big. |
334 | 334 | It simply means that the number is too big to put it into a 64~bit \pythonilIdx{float}.
|
335 | 335 |
|
336 | 336 | Actually, the \pythonilIdx{int} type can represent larger numbers easily.
|
337 |
| -\pythonil{1.7976931348623157e+308} is equivalent to \pythonil{17_976_931_348_623_157 * 10 ** 292}. |
| 337 | +\pythonilIdx{1.7976931348623157e+308}\pythonIdx{float!largest} is equivalent to \pythonil{17_976_931_348_623_157 * 10 ** 292}. |
338 | 338 | This prints as a number with many zeros.
|
339 |
| -Multiplying it with \pythonil{1.0} yields a \pythonilIdx{float} with value \pythonil{1.7976931348623157e+308}, exactly as expected. |
| 339 | +Multiplying it with \pythonil{1.0} yields a \pythonilIdx{float} with value \pythonilIdx{1.7976931348623157e+308}\pythonIdx{float!largest}, exactly as expected. |
340 | 340 | If we try a number ten times as large, i.e., \pythonil{17_976_931_348_623_157 * 10 ** 293}, this is no problem with the \pythonilIdx{int}.
|
341 | 341 | But we can no longer convert it to a \pythonilIdx{float} by multiplying with~\pythonil{1.0}.
|
342 | 342 | Trying to do that with a ten times larger number, i.e., computing \pythonil{17_976_931_348_623_157 * 10 ** 293 * 1.0} leads to an exception:
|
|
446 | 446 | The \pythonilIdx{math} module offers a set of functions to check whether a value is finite~(\pythonilIdx{isfinite}), infinite~(\pythonilIdx{isinf}), or \pythonil{nan}~(\pythonilIdx{isnan}).
|
447 | 447 |
|
448 | 448 | When doing floating point computations, these are the issues that you should aware about.
|
449 |
| -The precision and range is limited and strange things happen at its limits.% |
| 449 | +The precision and range is limited and strange things happen at these limits.% |
450 | 450 | %
|
451 | 451 | \endhsection%
|
452 | 452 | %
|
|
0 commit comments