[issue11680] decimal module generates AttributeError: on call to as_integer_ratio

2011-03-26 Thread Daniel Urban

Daniel Urban urban.dani...@gmail.com added the comment:

The problem seems to be that you're calling Decimal.from_float with a Decimal 
instance, not a float.  I'm not sure that should even work.  The Decimal 
constructor can create a decimal from an other decimal.

Your suggested solution probably would solve this exception, but I'm not sure 
it would be the good solution.  This way when creating a decimal from another 
decimal with from_float (which doesn't makes much sense, I think) could result 
in a loss of precision:

 Decimal(Decimal('0.9'))
Decimal('0.9')
 
 math.fabs(Decimal('0.9'))
1.0


--
nosy: +durban
type: crash - behavior
versions: +Python 3.1, Python 3.2, Python 3.3

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue11680
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue11680] decimal module generates AttributeError: on call to as_integer_ratio

2011-03-26 Thread Mark Dickinson

Mark Dickinson dicki...@gmail.com added the comment:

As Daniel says, from_float expects a float object, not a Decimal instance.

What did you want to achieve in the following line:

   self.from_float(value * decimal.Decimal(1.0))/decimal.Decimal(1.0)

?

By the way: in all current versions of Python, from_float is redundant:  you 
can create a Decimal directly from a float:


Python 2.7.1+ (2.7:d52b1faa7b11+, Mar 25 2011, 21:48:24) 
[GCC 4.2.1 (Apple Inc. build 5664)] on darwin
Type help, copyright, credits or license for more information.
 from decimal import Decimal
[64140 refs]
 Decimal(2.3)
Decimal('2.29982236431605997495353221893310546875')
[64149 refs]

--
nosy: +mark.dickinson
resolution:  - invalid
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue11680
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue11680] decimal module generates AttributeError: on call to as_integer_ratio

2011-03-25 Thread David Bailey

New submission from David Bailey daveabai...@gmail.com:

File C:\test3.py, line 166, in m
self.from_float(value * decimal.Decimal(1.0))/decimal.Decimal(1.0)
  File c:\Python27\lib\decimal.py, line 691, in from_float
n, d = abs(f).as_integer_ratio()
AttributeError: 'Decimal' object has no attribute 'as_integer_ratio'

line 691 in decimal.py 
  
n, d = abs(f).as_integer_ratio()

should be

n, d = _math.fabs(f).as_integer_ratio()

--
components: Library (Lib)
messages: 132194
nosy: daveabailey
priority: normal
severity: normal
status: open
title: decimal module generates AttributeError: on call to as_integer_ratio
type: crash
versions: Python 2.7

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue11680
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com