[Python-checkins] python/nondist/peps pep-0327.txt,1.1,1.2

goodger at users.sourceforge.net goodger at users.sourceforge.net
Wed Mar 31 11:24:03 EST 2004


Update of /cvsroot/python/python/nondist/peps
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10738

Modified Files:
	pep-0327.txt 
Log Message:
updates from Facundo Batista, with edits

Index: pep-0327.txt
===================================================================
RCS file: /cvsroot/python/python/nondist/peps/pep-0327.txt,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** pep-0327.txt	29 Jan 2004 19:59:56 -0000	1.1
--- pep-0327.txt	31 Mar 2004 16:24:00 -0000	1.2
***************
*** 9,13 ****
  Created: 17-Oct-2003
  Python-Version: 2.4
! Post-History: 30-Nov-2003, 02-Jan-2004
  
  
--- 9,13 ----
  Created: 17-Oct-2003
  Python-Version: 2.4
! Post-History: 30-Nov-2003, 02-Jan-2004, 29-Jan-2004
  
  
***************
*** 401,419 ****
  affects just operations' results.
  
! **From int or long**: There's no loss and no need to specify any other
! information::
  
      Decimal(35)
      Decimal(-124)
  
! **From string**: Strings with floats in normal and engineering
! notation will be supported.  In this transformation there is no loss
! of information, as the string is directly converted to Decimal (there
! is not an intermediate conversion through float)::
  
      Decimal("-12")
      Decimal("23.2e-7")
  
! **From float**: The initial discussion on this item was what should
  happen when passing floating point to the constructor:
  
--- 401,430 ----
  affects just operations' results.
  
! 
! From int or long
! ''''''''''''''''
! 
! There's no loss and no need to specify any other information::
  
      Decimal(35)
      Decimal(-124)
  
! 
! From string
! '''''''''''
! 
! Strings with floats in normal and engineering notation will be
! supported.  In this transformation there is no loss of information, as
! the string is directly converted to Decimal (there is not an
! intermediate conversion through float)::
  
      Decimal("-12")
      Decimal("23.2e-7")
  
! 
! From float
! ''''''''''
! 
! The initial discussion on this item was what should
  happen when passing floating point to the constructor:
  
***************
*** 461,474 ****
      a substantial risk of tricking naive users.
  
! So, I think that the best solution is to have a parameter that says in
! which position after the decimal point you apply a round-half-up
! rounding.  If you do not specify this parameter, you get an exact
! conversion. In this way::
  
!     Decimal(1.1, 2) == Decimal('1.1')
!     Decimal(1.1, 16) == Decimal('1.1000000000000001')
!     Decimal(1.1) == Decimal('110000000000000008881784197001252...e-51')
  
! **From tuples**: Aahz suggested to construct from tuples: it's easier
  to implement ``eval()``'s round trip and "someone who has numeric
  values representing a Decimal does not need to convert them to a
--- 472,494 ----
      a substantial risk of tricking naive users.
  
! So, the accepted solution through c.l.p is that you can not call Decimal
! with a float. Instead you must use a method: Decimal.from_float(). The
! syntax::
  
!     Decimal.from_float(floatNumber, [positions])
!     
! where ``floatNumber`` is the float number origin of the construction and
! ``positions`` is the positions after the decimal point where you apply a
! round-half-up rounding, if any.  In this way you can do, for example::
  
!     Decimal.from_float(1.1, 2): The same that doing Decimal('1.1').
!     Decimal.from_float(1.1, 16): The same that doing Decimal('1.1000000000000001').
!     Decimal.from_float(1.1): The same that doing Decimal('110000000000000008881784197001252...e-51').
! 
! 
! From tuples
! '''''''''''
! 
! Aahz suggested to construct from tuples: it's easier
  to implement ``eval()``'s round trip and "someone who has numeric
  values representing a Decimal does not need to convert them to a
***************
*** 481,492 ****
      Decimal((1, (3, 2, 2, 5), -2))     # for -32.25
  
- **From Decimal**: No mystery here, just a copy.
  
! **Syntax to all the cases**::
  
!     Decimal(value, [decimal_digits])
  
! where ``value`` can be any of the data types just mentioned and
! ``decimal_digits`` is allowed only when value is float.
  
  
--- 501,522 ----
      Decimal((1, (3, 2, 2, 5), -2))     # for -32.25
  
  
! From Decimal
! ''''''''''''
  
! No mystery here, just a copy.
  
! 
! Syntax for All Cases
! ''''''''''''''''''''
! 
! ::
! 
!     Decimal(value1)
!     Decimal.from_float(value2, [decimal_digits])
! 
! where ``value1`` can be int, long, string, tuple or Decimal,
! ``value1`` can be only float, and ``decimal_digits`` is an optional
! int.
  
  
***************
*** 510,522 ****
  So, here I define the behaviour again for each data type.
  
- **From int or long**: Aahz suggested the need of an explicit
- conversion from int, but also thinks it's OK if the precision in the
- current Context is not exceeded; in that case you raise ValueError.
- Votes in comp.lang.python agreed with this.
  
! **From string**: Everybody agrees to raise an exception here.
  
! **From float**: Aahz is strongly opposed to interact with float,
! suggesting an explicit conversion:
  
      The problem is that Decimal is capable of greater precision,
--- 540,564 ----
  So, here I define the behaviour again for each data type.
  
  
! From int or long
! ''''''''''''''''
  
! Aahz suggested the need of an explicit conversion from int, but also
! thinks it's OK if the precision in the current Context is not
! exceeded; in that case you raise ValueError.  Votes in
! comp.lang.python agreed with this.
! 
! 
! From string
! '''''''''''
! 
! Everybody agrees to raise an exception here.
! 
! 
! From float
! ''''''''''
! 
! Aahz is strongly opposed to interact with float, suggesting an
! explicit conversion:
  
      The problem is that Decimal is capable of greater precision,
***************
*** 534,538 ****
  ``Decimal(35) + 1.1`` raises an error).
  
! **From Decimal**: There isn't any issue here.
  
  
--- 576,587 ----
  ``Decimal(35) + 1.1`` raises an error).
  
! This resulted to be too tricky. So tricky, that c.l.p agreed to raise
! TypeError in this case: you could not mix Decimal and float.
! 
! 
! From Decimal
! ''''''''''''
! 
! There isn't any issue here.
  
  




More information about the Python-checkins mailing list