Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #62506

Re: Why Python is like C++

References (3 earlier) <mailman.4451.1387603576.18130.python-list@python.org> <bhl0glF7cd9U1@mid.individual.net> <l93pui$8gr$1@dont-email.me> <mailman.4472.1387638502.18130.python-list@python.org> <roy-867FD6.10590021122013@news.panix.com>
Date 2013-12-22 06:04 +1100
Subject Re: Why Python is like C++
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.4479.1387652653.18130.python-list@python.org> (permalink)

Show all headers | View raw


On Sun, Dec 22, 2013 at 2:59 AM, Roy Smith <roy@panix.com> wrote:
> In article <mailman.4472.1387638502.18130.python-list@python.org>,
>  Tim Chase <python.list@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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Why Python is like C++ Roy Smith <roy@panix.com> - 2013-12-20 09:19 -0500
  Re: Why Python is like C++ Serhiy Storchaka <storchaka@gmail.com> - 2013-12-20 19:46 +0200
    Re: Why Python is like C++ Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2013-12-21 10:44 +1300
      Re: Why Python is like C++ Michael Torrie <torriem@gmail.com> - 2013-12-20 22:25 -0700
        Re: Why Python is like C++ Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2013-12-21 21:06 +1300
          Re: Why Python is like C++ Chris Angelico <rosuav@gmail.com> - 2013-12-21 19:17 +1100
          Re: Why Python is like C++ Christian Gollwitzer <auriocus@gmx.de> - 2013-12-21 11:19 +0100
            Re: Why Python is like C++ Tim Chase <tim@thechases.com> - 2013-12-21 08:52 -0600
              Re: Why Python is like C++ Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2013-12-22 13:17 +1300
            Re: Why Python is like C++ Tim Chase <python.list@tim.thechases.com> - 2013-12-21 08:43 -0600
              Re: Why Python is like C++ Roy Smith <roy@panix.com> - 2013-12-21 10:59 -0500
                Re: Why Python is like C++ Tim Chase <python.list@tim.thechases.com> - 2013-12-21 10:29 -0600
                Re: Why Python is like C++ Chris Angelico <rosuav@gmail.com> - 2013-12-22 06:04 +1100
              Re: Why Python is like C++ Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2013-12-22 13:27 +1300
            Re: Why Python is like C++ Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2013-12-22 13:14 +1300
          Re: Why Python is like C++ Michael Torrie <torriem@gmail.com> - 2013-12-21 08:46 -0700
            Re: Why Python is like C++ Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2013-12-22 13:36 +1300
  Re: Why Python is like C++ Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-12-21 05:34 +0000
    Re: Why Python is like C++ Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2013-12-21 21:09 +1300
      Re: Why Python is like C++ Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-12-21 08:22 +0000
    Re: Why Python is like C++ Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-12-21 11:37 +0000
      Re: Why Python is like C++ Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-12-21 12:12 +0000
  Re: Why Python is like C++ Dan Stromberg <drsalists@gmail.com> - 2013-12-21 00:18 -0800
    Re: Why Python is like C++ Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-12-21 11:51 +0000
    Re: Why Python is like C++ Roy Smith <roy@panix.com> - 2013-12-21 10:10 -0500
      Re: Why Python is like C++ Terry Reedy <tjreedy@udel.edu> - 2013-12-21 17:03 -0500
        Re: Why Python is like C++ Roy Smith <roy@panix.com> - 2013-12-21 17:28 -0500
          Re: Why Python is like C++ Terry Reedy <tjreedy@udel.edu> - 2013-12-21 19:20 -0500
  Re: Why Python is like C++ Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-12-21 08:42 +0000
  Re: Why Python is like C++ Gene Heskett <gheskett@wdtv.com> - 2013-12-21 14:05 -0500

csiph-web