Article Preview
Buy Now
COLUMN
Large, Big, and Bigger Numbers
Working with giant numbers
Issue: 21.3 (May/June 2023)
Author: Stefanie Juchmes
Author Bio: Stefanie studied computer science at the university in Bonn. She came in touch with Xojo due to the work of her brother-in-law and got a junior developer position in early 2019 at Monkeybread Software.
Article Description: No description available.
Article Length (in bytes): 7,398
Starting Page Number: 66
Article Number: 21307
Resource File(s):
project-21307.zip Updated: 2023-05-05 09:39:18
Related Link(s): None
Excerpt of article text...
In this Spotlight article today I would like to introduce you to the Math section of the MBS Xojo plugins. This section was created for developers who need accurate and fast calculations in their applications. If you are a physicist, mathematician, chemist, or just a math enthusiast, you might be interested in this article.
One, Two, Overflow
Every number that we store in the computer has a certain length that is fixed. For example, an integer number in Xojo that runs in a 64-bit application can be 8 bytes (8 * 8 = 64 bits) long and have a range of values from
-9,223,372,036,854,775,808
to+9,223,372,036,854,775,807
.If we enter a value that is not in this range, an
overflow will occur and a wrong number will be returned as the result (see Figure 1). Such an overflow can have fatal consequences that must be avoided if you can get results that extend beyond this range. If we use aUInteger
we have at least a coverage of positive integers up to18,446,744,073,709,551,615
but even this is sometimes not enough.For decimal numbers we have two different approaches. On the one hand, the fixed point numbers like the type
Currency
which allow a maximum of four decimal places and thus go from a range of-922337203685477.5808
to922337203685477.5807
. Here the decimal point sits in a fixed place and cannot be moved.Or we have floating point numbers. These have an enormously high range width with numbers that range between
?1.79769313486231570814527423731704357e+308
as adouble
. But here we have another problem, because they usually cannot be representedexactly . For example, if we have the number6.1
, it will be displayed as6.0999999999999996
in the debugger, which can lead to rounding errors in calculations and can have catastrophic consequences (see Figure 2). But what can you do if you need this accuracy?
...End of Excerpt. Please purchase the magazine to read the full article.