On Sun, Dec 22, 2013 at 2:59 AM, Roy Smith <r...@panix.com> wrote: > In article <mailman.4472.1387638502.18130.python-l...@python.org>, > Tim Chase <python.l...@tim.thechases.com> wrote: > >> In know that my first BASIC, Applesoft BASIC had the 2-character >> names, and you had to load Integer Basic (with Ints in addition to the >> standard Floats used in the BASIC provided by the ROM, a strange >> choice). > > Why is it a strange choice? If you're only going to support a single > type of numeric value, floats make a lot more sense than ints. Floats > are a superset of integers.
No, reals are a superset of integers, and are also a superset of floats. Whether a float can precisely represent every int in your pool depends on their relative sizes; in another thread we've just had complaints about fixed-size integers in C, but they do simplify discussions like this! With IEEE floating point, it's theoretically possible to represent any integer smaller than 2**M, where M is the size of the mantissa (including its leading 1 bit). In practical terms, that means your float has to take up twice as much space as an int would (a 64-bit float has a 53-bit mantissa, so it can represent 32-bit numbers - nobody actually asks for 53-bit integer support, but you do have it). I don't know about non-IEEE float systems, but they'll be doing something similar. Arbitrary precision throws a whole new spanner in the works. It's pretty easy to offer an arbitrary-precision integer type that guarantees accuracy down to the last digit. Offering a float type that can represent a ridiculous range of integers is problematic. I notice that Python offers the former and not the latter :) REXX offered configurable-precision numeric calculations, but performance dropped off badly as the precision rose. That is to say, it was fine for the default 9 digits, fine for 100 digits (but now you have to format numbers for display, or they'll be ugly), starting to get slow if you asked for 500 digits, and really quite ridiculously slow with NUMERIC DIGITS 10000. I wouldn't say that most languages' float type is truly a superset of int. ChrisA -- https://mail.python.org/mailman/listinfo/python-list