Re: Floating point overflow and underflow

2020-01-07 Thread Shashank Tiwari
Oh, thanks. Didn't think of that. On Tue, Jan 7, 2020, 7:53 PM Michael Torrie wrote: > On 1/7/20 8:46 PM, Shashank Tiwari wrote: > > Yes, I tried this and it worked. I was wondering if I could use the > output > > of pow (or math.pow). > > Sure: > > pow(Decimal('2.2'), Decimal('0.45')) > > -- >

Re: Floating point overflow and underflow

2020-01-07 Thread Michael Torrie
On 1/7/20 8:46 PM, Shashank Tiwari wrote: > Yes, I tried this and it worked. I was wondering if I could use the output > of pow (or math.pow). Sure: pow(Decimal('2.2'), Decimal('0.45')) -- https://mail.python.org/mailman/listinfo/python-list

Re: Floating point overflow and underflow

2020-01-07 Thread Shashank Tiwari
Thanks everyone. Much appreciated. On Tue, Jan 7, 2020, 7:46 PM Shashank Tiwari wrote: > Yes, I tried this and it worked. I was wondering if I could use the output > of pow (or math.pow). > > On Tue, Jan 7, 2020, 7:41 PM Michael Torrie wrote: > >> On 1/7/20 8:18 PM, Shashank Tiwari wrote: >> >

Re: Floating point overflow and underflow

2020-01-07 Thread Shashank Tiwari
Yes, I tried this and it worked. I was wondering if I could use the output of pow (or math.pow). On Tue, Jan 7, 2020, 7:41 PM Michael Torrie wrote: > On 1/7/20 8:18 PM, Shashank Tiwari wrote: > > Thanks Chris. What if it's pow(2.2,0.45)? > > Why not do some more experimentation: > > >>> import d

Re: Floating point overflow and underflow

2020-01-07 Thread Michael Torrie
On 1/7/20 8:18 PM, Shashank Tiwari wrote: > Thanks Chris. What if it's pow(2.2,0.45)? Why not do some more experimentation: >>> import decimal >>> a = decimal.Decimal('2.2') >>> b = decimal.Decimal('0.45') >>> a ** b Decimal('1.425903734234490793207619170') Is this what you mean? I'm sure there

Re: Floating point overflow and underflow

2020-01-07 Thread Chris Angelico
On Wed, Jan 8, 2020 at 2:18 PM Shashank Tiwari wrote: > > Thanks Chris. What if it's pow(2.2,0.45)? > Initialize your Decimals from strings, as you were already advised, and do the calculation in Decimals. Or just use floats, since it's likely to be at least as accurate. ChrisA -- https://mail

Re: Floating point overflow and underflow

2020-01-07 Thread Shashank Tiwari
Thanks Chris. What if it's pow(2.2,0.45)? On Tue, Jan 7, 2020, 6:40 PM Chris Angelico wrote: > On Wed, Jan 8, 2020 at 1:37 PM Shashank Tiwari > wrote: > > > > Thanks Rob. > > > > How would one initialize a Decimal with something like pow(2,256)? > > > > Easy, just initialize it with an integer:

Re: Floating point overflow and underflow

2020-01-07 Thread Chris Angelico
On Wed, Jan 8, 2020 at 1:37 PM Shashank Tiwari wrote: > > Thanks Rob. > > How would one initialize a Decimal with something like pow(2,256)? > Easy, just initialize it with an integer: >>> Decimal(2**256) Decimal('115792089237316195423570985008687907853269984665640564039457584007913129639936')

Re: Floating point overflow and underflow

2020-01-07 Thread Shashank Tiwari
Thanks Rob. How would one initialize a Decimal with something like pow(2,256)? On Tue, Jan 7, 2020 at 5:25 PM Rob Gaddi wrote: > On 1/7/20 3:47 PM, Shashank Tiwari wrote: > > In Python3 an operation as follows: > 10135.1941 * (10**8) > > gives the result: 101351941.0001 > > > > Similar

Re: Floating point overflow and underflow

2020-01-07 Thread Rob Gaddi
On 1/7/20 3:47 PM, Shashank Tiwari wrote: In Python3 an operation as follows: 10135.1941 * (10**8) gives the result: 101351941.0001 Similarly, using the pow function also gives the same overflow/underflow error. 10135.1941 * pow(10,8) 101351941.0001 Like multiplication, division of

Floating point overflow and underflow

2020-01-07 Thread Shashank Tiwari
In Python3 an operation as follows: >>> 10135.1941 * (10**8) gives the result: 101351941.0001 Similarly, using the pow function also gives the same overflow/underflow error. >>> 10135.1941 * pow(10,8) 101351941.0001 Like multiplication, division of large or very small floating point numbe