Why is Double larger than Int64

A 64bit Double can hold much larger values than a 64bit Integer - how???

Floating-point types can represent a much wider range of values than integer types, and can store numbers that are much larger or smaller than can be stored in an Int . Swift provides two signed floating-point number types:

  • Double represents a 64-bit floating-point number.
  • Float represents a 32-bit floating-point number.

Same is true for Xojo - but why?

A 64bit Double can hold much larger values than a 64bit Integer - how???

Doubles are less precise
A 64 bit integer is 100% accurate through ALL values in the range it can hold
Not so for a Double - there are wide gaps in accuracy

Same is true for Xojo - but why?

Why ? why 2 types ? or something else ?
2 types is/was legacy in some cases - old FPU’s used to directly support one in hardware and the other in software. Thats no longer the case on most modern CPU’s
But they also can represent different ranges with different degrees of accuracy
See https://en.wikipedia.org/wiki/IEEE_754

That can‘t be the answer. Let‘s ignore for a moment that Doubles use some bits for fractions. Even then there are just 64bits available.

So Doubles must use part of those 64 bits as (base 10? 16?) exponents - otherwise they could never be bigger than Int64 …

In an int ALL the bits represent the value
In a double or single some are the value and some are the exponent
And so they have fewer bits to represent the value - therefor less precision
But since they use a biased exponent they can represent a much wider range
The wikipedia article does explain this pretty reasonably


Look up floating-point format here:

Yeah, should have looked at Wikipedia immediately. My bad.

No problem

Its not intuitive for sure since in memory they both occupy 8 bytes

But, like so many things in computing, its not that they use X many bytes its how those bytes are interpreted as a specific kind of data that matters

I mean is &hf0 signed or unsigned ?
You cant tell just from the contents of a byte
It could be a 1 byte character, a Uint8, a signed Int8 or any one of several other kinds of things

And this is where the TYPE in a language like Xojo comes into play. Thats the hint to the compiler that you want this byte treated as whatever TYPE you said on the DIM line

Its so much fun !