[Python-checkins] CVS: python/nondist/peps pep-0242.txt,1.1,1.2

Barry Warsaw bwarsaw@users.sourceforge.net
Tue, 17 Apr 2001 09:31:16 -0700


Update of /cvsroot/python/python/nondist/peps
In directory usw-pr-cvs1:/tmp/cvs-serv24784

Modified Files:
	pep-0242.txt 
Log Message:
Paul's latest revision, with some formatting and spell-checking
corrections by Barry.


Index: pep-0242.txt
===================================================================
RCS file: /cvsroot/python/python/nondist/peps/pep-0242.txt,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** pep-0242.txt	2001/03/20 05:29:16	1.1
--- pep-0242.txt	2001/04/17 16:31:14	1.2
***************
*** 40,78 ****
  
  
! Supported Kinds
  
      Each Python compiler may define as many "kinds" of integer and
      floating point numbers as it likes, except that it must support at
      least two kinds of integer corresponding to the existing int and
      long, and must support at least one kind of floating point number,
!     equivalent to the present float.  The range and precision of the
!     these kinds are processor dependent, as at present, except for the
!     "long integer" kind, which can hold an arbitrary integer.  The
!     built-in functions int(), float(), long() and complex() convert
!     inputs to these default kinds as they do at present.  (Note that a
      Unicode string is actually a different "kind" of string and that a
      sufficiently knowledgeable person might be able to expand this PEP
      to cover that case.)
  
!     Within each type (integer, floating, and complex) the compiler
!     supports a linearly-ordered set of kinds, with the ordering
!     determined by the ability to hold numbers of an increased range
!     and/or precision.
  
  
  Kind Objects
  
!     Three new standard functions are defined in a module named
!     "kinds".  They return callable objects called kind objects.  Each
!     int or floating kind object f has the signature result = f(x), and
!     each complex kind object has the signature result = f(x, y=0.).
  
      int_kind(n)
!         For n >= 1, return a callable object whose result is an
!         integer kind that will hold an integer number in the open
!         interval (-10**n,10**n).  This function always succeeds, since
!         it can return the 'long' kind if it has to. The kind object
!         accepts arguments that are integers including longs.  If n ==
!         0, returns the kind object corresponding to long.
  
      float_kind(nd, n)
--- 40,82 ----
  
  
! Supported Kinds of Ints and Floats
  
+     Complex numbers are treated separately below, since Python can be
+     built without them.
+ 
      Each Python compiler may define as many "kinds" of integer and
      floating point numbers as it likes, except that it must support at
      least two kinds of integer corresponding to the existing int and
      long, and must support at least one kind of floating point number,
!     equivalent to the present float.
!     
!     The range and precision of the these required kinds are processor
!     dependent, as at present, except for the "long integer" kind,
!     which can hold an arbitrary integer.
! 
!     The built-in functions int(), long(), and float() convert inputs
!     to these default kinds as they do at present.  (Note that a
      Unicode string is actually a different "kind" of string and that a
      sufficiently knowledgeable person might be able to expand this PEP
      to cover that case.)
  
!     Within each type (integer, floating) the compiler supports a
!     linearly-ordered set of kinds, with the ordering determined by the
!     ability to hold numbers of an increased range and/or precision.
  
  
  Kind Objects
  
!     Two new standard functions are defined in a module named "kinds".
!     They return callable objects called kind objects.  Each int or
!     floating kind object f has the signature result = f(x), and each
!     complex kind object has the signature result = f(x, y=0.).
  
      int_kind(n)
!         For an integer argument n >= 1, return a callable object whose
!         result is an integer kind that will hold an integer number in
!         the open interval (-10**n,10**n).  The kind object accepts
!         arguments that are integers including longs.  If n == 0,
!         returns the kind object corresponding to the Python literal 0.
  
      float_kind(nd, n)
***************
*** 80,92 ****
          is a floating point kind that will hold a floating-point
          number with at least nd digits of precision and a base-10
!         exponent in the open interval (-n, n).  The kind object
!         accepts arguments that are integer or real.
  
!     complex_kind(nd, n)
!         Return a callable object whose result is a complex kind that
!         will will hold a complex number each of whose components
!         (.real, .imag) is of kind float_kind(nd, n).  The kind object
!         will accept one argument that is integer, real, or complex, or
!         two arguments, each integer or real.
  
      The compiler will return a kind object corresponding to the least
--- 84,92 ----
          is a floating point kind that will hold a floating-point
          number with at least nd digits of precision and a base-10
!         exponent in the closed interval [-n, n].  The kind object
!         accepts arguments that are integer or float.
  
!         If nd and n are both zero, returns the kind object
!         corresponding to the Python literal 0.0.
  
      The compiler will return a kind object corresponding to the least
***************
*** 98,151 ****
      exception is thrown.
  
-     Kind objects also accept a string argument for conversion of
-     literal notation to their kind.
- 
      Besides their callable behavior, kind objects have attributes
!     giving the traits of the kind in question.  The list of traits
!     needs to be completed.
  
  
! The Meaning of Literal Values
  
!     Literal integer values without a trailing L are of the least
!     integer kind required to represent them.  An integer literal with
!     a trailing L is a long.  Literal decimal values are of the
!     greatest available binary floating-point kind.
  
  
- Concerning Infinite Floating Precision
  
!     This section makes no proposals and can be omitted from
!     consideration.  It is for illuminating an intentionally
!     unimplemented 'corner' of the design.
!     
!     This PEP does not propose the creation of an infinite precision
!     floating point type, just leaves room for it.  Just as int_kind(0)
!     returns the long kind object, if in the future an infinitely
!     precise decimal kind is available, float_kind(0,0) could return a
!     function that converts to that type.  Since such a kind function
!     accepts string arguments, programs could then be written that are
!     completely precise.  Perhaps in analogy to r'a raw string', 1.3r
!     might be available as syntactic sugar for calling the infinite
!     floating kind object with argument '1.3'.  r could be thought of
!     as meaning 'rational'.
! 
! 
! Complex numbers and kinds
! 
!     Complex numbers are always pairs of floating-point numbers with
!     the same kind.  A Python compiler must support a complex analog of
!     each floating point kind it supports, if it supports complex
!     numbers at all.
! 
! 
! Coercion
! 
!     In an expression, coercion between different kinds is to the
!     greater kind.  For this purpose, all complex kinds are "greater
!     than" all floating-point kinds, and all floating-point kinds are
!     "greater than" all integer kinds.
  
  
  Examples
  
--- 98,175 ----
      exception is thrown.
  
      Besides their callable behavior, kind objects have attributes
!     giving the traits of the kind in question.
  
+     1. name is the name of the kind.  The standard kinds are called
+        int, long, double.
  
!     2. typecode is a single-letter string that would be appropriate
!        for use with Numeric or module array to form an array of this
!        kind.  The standard types' typecodes are 'i', 'O', 'd'
!        respectively.
  
!     3. Integer kinds have these additional attributes: MAX, equal to
!        the maximum permissible integer of this kind, or None for the
!        long kind.  MIN, equal to the most negative permissible integer
!        of this kind, or None for the long kind.
  
+     4. Float kinds have these additional attributes whose properties
+        are equal to the corresponding value for the corresponding C
+        type in the standard header file "float.h".  MAX, MIN, DIG,
+        MANT_DIG, EPSILON, MAX_EXP, MAX_10_EXP, MIN_EXP, MIN_10_EXP,
+        RADIX, ROUNDS (== FLT_RADIX, FLT_ROUNDS in float.h).  These
+        values are of type integer except for MAX, MIN, and EPSILON,
+        which are of the Python floating type to which the kind
+        corresponds.
  
  
! Attributes of Module kinds
! 
!     int_kinds is a list of the available integer kinds, sorted from lowest
!               to highest kind.  By definition, int_kinds[-1] is the
!               long kind.
! 
!     float_kinds is a list of the available floating point kinds, sorted
!                 from lowest to highest kind.
! 
!     default_int_kind is the kind object corresponding to the Python 
!                      literal 0
! 
!     default_long_kind is the kind object corresponding to the Python
!                       literal 0L
  
+     default_float_kind is the kind object corresponding to the Python
+                        literal 0.0
  
+ 
+ Complex Numbers
+ 
+     If supported, complex numbers have real and imaginary parts that
+     are floating-point numbers with the same kind.  A Python compiler
+     must support a complex analog of each floating point kind it
+     supports, if it supports complex numbers at all.
+ 
+     If complex numbers are supported, the following are available in
+     module kinds:
+ 
+     complex_kind(nd, n)
+         Return a callable object whose result is a complex kind that
+         will hold a complex number each of whose components (.real,
+         .imag) is of kind float_kind(nd, n).  The kind object will
+         accept one argument that is of any integer, real, or complex
+         kind, or two arguments, each integer or real.
+ 
+     complex_kinds is a list of the available complex kinds, sorted 
+                   from lowest to highest kind.
+ 
+     default_complex_kind is the kind object corresponding to the
+                          Python literal 0.0j.  The name of this kind
+                          is doublecomplex, and its typecode is 'D'.
+                               
+     Complex kind objects have these addition attributes:
+ 
+     floatkind is the kind object of the corresponding float type.
+ 
+ 
  Examples
  
***************
*** 166,170 ****
--- 190,196 ----
          # builtin float gets you the default float kind, properties unknown
          w = x * float(x)
+         # but in the following case we know w has kind "double".
          w = x * double(z)
+ 
          u = csingle(x + z * 1.0j)
          u2 = csingle(x+z, 1.0)
***************
*** 180,195 ****
  
  Open Issues
- 
-     The assertion that a decimal literal means a binary floating-point
-     value of the largest available kind is in conflict with other
-     proposals about Python's numeric model.  This PEP asserts that
-     these other proposals are wrong and that part of them should not
-     be implemented.
- 
-     Determine the exact list of traits for integer and floating point
-     numbers.  There are some standard Fortran routines that do this
-     but I have to track them down.  Also there should be information
-     sufficient to create a Numeric array of an equal or greater kind.
  
  
  Copyright
--- 206,211 ----
  
  Open Issues
  
+     No open issues have been raised at this time.
  
  Copyright