Re: Decimals and other numbers

2015-01-10 Thread alister
On Fri, 09 Jan 2015 19:57:20 -0800, Devin Jeanpierre wrote: > On Fri, Jan 9, 2015 at 7:05 PM, Gregory Ewing > wrote: >> It's far from clear what *anything* multiplied by itself zero times >> should be. >> >> A better way of thinking about what x**n for integer n means is this: >> Start with 1, an

Re: Decimals and other numbers

2015-01-09 Thread Devin Jeanpierre
On Fri, Jan 9, 2015 at 7:05 PM, Gregory Ewing wrote: > It's far from clear what *anything* multiplied by > itself zero times should be. > > A better way of thinking about what x**n for integer > n means is this: Start with 1, and multiply it by > x n times. The result of this is clearly 1 when n >

Re: Decimals and other numbers

2015-01-09 Thread Gregory Ewing
Steven D'Aprano wrote: I'm just sketching an informal proof. If you want to make it vigorous I think the usual term is "rigorous", unless the mathematician is taking some kind of stimulant... :-) -- Greg -- https://mail.py

Re: Decimals and other numbers

2015-01-09 Thread Gregory Ewing
Steven D'Aprano wrote: Arguably, *integer* 0**0 could be zero, on the basis that you can't take limits of integer-valued quantities, and zero times itself zero times surely has to be zero. It's far from clear what *anything* multiplied by itself zero times should be. A better way of thinking a

Re: Decimals and other numbers

2015-01-09 Thread Devin Jeanpierre
On Fri, Jan 9, 2015 at 2:20 AM, Steven D'Aprano wrote: -snip- > I don't understand what you're trying to say here. You can't just > arbitrarily declare that 0**1 equals something other than 0 (or for that > matter, doesn't equal anything at all). You can, actually. It's just silly. (Similarly, yo

Re: Decimals and other numbers

2015-01-09 Thread Chris Angelico
On Fri, Jan 9, 2015 at 11:24 PM, Steven D'Aprano wrote: >> 5 * 0 * 0 * 0 * 0 = 0 > > Where did the 5 come from? > > You're effectively saying that 0**0 becomes 5*0**0, then cancelling the 0**0 > because they're all zeroes and so don't matter, leaving 5. And that simply > doesn't work. If it did wo

Re: Decimals and other numbers

2015-01-09 Thread Steven D'Aprano
I want to emphasis that I'm not really arguing that 0**0 should evaluate as 0. That's probably the least useful thing we can have out of the four possibilities: - return 1 - return NAN - raise an exception - return 0 But in the spirit of the Devil's Advocate, I mentioned that there was an argumen

Re: Decimals and other numbers

2015-01-09 Thread Steven D'Aprano
Marko Rauhamaa wrote: > Steven D'Aprano : > >> mathematicians with a pragmatic bent > > You shouldn't call engineers and scientists mathematicians ("with a > pragmatic bent"). Rigor is an absolute requirement for any mathematics. I wasn't referring to engineers, scientists, short-order cooks or

Re: Decimals and other numbers

2015-01-09 Thread Chris Angelico
On Fri, Jan 9, 2015 at 9:20 PM, Steven D'Aprano wrote: > On the basis that m**n means m multiplied by itself n times: > > 5**4 = 5*5*5*5 = 625 > > that gives us: > > 0**0 = zero multiplied by itself zero times. > > You can multiply 0 by any number you like, and the answer will always be 0, > not 1

Re: Decimals and other numbers

2015-01-09 Thread Steven D'Aprano
I think we're in violent agreement here, nevertheless I think you're right for the wrong reasons. See below... Devin Jeanpierre wrote: > On Fri, Jan 9, 2015 at 12:49 AM, Steven D'Aprano > wrote: >> Devin Jeanpierre wrote: >> >>> On Thu, Jan 8, 2015 at 6:43 PM, Dave Angel wrote: What you d

Re: Decimals and other numbers

2015-01-09 Thread Marko Rauhamaa
Steven D'Aprano : > Devin Jeanpierre wrote: > No you can't -- that would make arithmetic inconsistent. 0**1 is > perfectly well defined as 0 however you look at it: You *could* leave 0**1 undefined. You *could* leave 7+0 undefined. However, that would make mathematical proofs more complex as they

Re: Decimals and other numbers

2015-01-09 Thread Marko Rauhamaa
Steven D'Aprano : > mathematicians with a pragmatic bent You shouldn't call engineers and scientists mathematicians ("with a pragmatic bent"). Rigor is an absolute requirement for any mathematics. Marko -- https://mail.python.org/mailman/listinfo/python-list

Re: Decimals and other numbers

2015-01-09 Thread Marko Rauhamaa
Chris Angelico : > I'm not a mathematical expert, so I don't quite 'get' this. How does > this justify 0**0 being equal to 0.5? Many operations like this are defined in terms of some very strong argument of uniqueness. Ultimately, the key point is safety in mathematical deductions. One minimal re

Re: Decimals and other numbers

2015-01-09 Thread Devin Jeanpierre
On Fri, Jan 9, 2015 at 12:58 AM, Devin Jeanpierre wrote: >> Arguably, *integer* 0**0 could be zero, on the basis that you can't take >> limits of integer-valued quantities, and zero times itself zero times >> surely has to be zero. I should have responded in more detail here, sorry. If you aren'

Re: Decimals and other numbers

2015-01-09 Thread Jussi Piitulainen
Devin Jeanpierre writes: [...] > domain of the natural numbers. Knuth says that thought of > combinatorially on the naturals, x**y counts the number of mappings > from a set of x values to a set of y values. It's the other way around, of course: from a set of y values to a set of x values. Whi

Re: Decimals and other numbers

2015-01-09 Thread Devin Jeanpierre
l theorem is to be valid when x=0, > y=0, and/or x=-y. The theorem is too important to be arbitrarily > restricted! By contrast, the function 0^x is quite unimportant. > > More discussion here: > > http://mathforum.org/dr.math/faq/faq.0.to.0.power.html I've already been c

Re: Decimals and other numbers

2015-01-09 Thread Devin Jeanpierre
Marko, your argument is "this function x**y(a, x) must be continuous on [0, inf), and to be continuous at 0, 0**0 must be a". Since there are many possible values of a, this is not a "justification", this is a proof by contradiction that the premise was faulty: x**y(a, x) doesn't have to be continu

Re: Decimals and other numbers

2015-01-09 Thread Steven D'Aprano
By contrast, the function 0^x is quite unimportant. More discussion here: http://mathforum.org/dr.math/faq/faq.0.to.0.power.html > I expected 1, nan, or an exception, but more importantly, I expected > it to be the same for floats and decimals. Arguably, *integer* 0**0 could be zero, on th

Re: Decimals and other numbers

2015-01-08 Thread Dave Angel
On 01/09/2015 02:37 AM, Chris Angelico wrote: On Fri, Jan 9, 2015 at 6:28 PM, Marko Rauhamaa wrote: Devin Jeanpierre : If 0**0 is defined, it must be 1. You can "justify" any value a within [0, 1]. For example, choose y(a, x) = log(a, x) Then, limy(a, x) = 0 x -> 0+ and

Re: Decimals and other numbers

2015-01-08 Thread Chris Angelico
On Fri, Jan 9, 2015 at 6:28 PM, Marko Rauhamaa wrote: > Devin Jeanpierre : > >> If 0**0 is defined, it must be 1. > > You can "justify" any value a within [0, 1]. For example, choose > >y(a, x) = log(a, x) > > Then, > > limy(a, x) = 0 >x -> 0+ > > and: > >lim[x -> 0+] x**y(a, x

Re: Decimals and other numbers

2015-01-08 Thread Marko Rauhamaa
Devin Jeanpierre : > If 0**0 is defined, it must be 1. You can "justify" any value a within [0, 1]. For example, choose y(a, x) = log(a, x) Then, limy(a, x) = 0 x -> 0+ and: lim[x -> 0+] x**y(a, x) = a For example, >>> a = 0.5 >>> x = 1e-100 >>> y = math.log(a, x)

Re: Decimals and other numbers

2015-01-08 Thread Marko Rauhamaa
Dave Angel : > What you don't say is which behavior you actually expected. Since 0**0 > is undefined mathematically, I'd expect either an exception or a NAN > result. IEEE 754 mandates that 0**0 should evaluate to 1: http://en.wikipedia.org/wiki/NaN#Operations_generating_NaN> The standar

Re: Decimals and other numbers

2015-01-08 Thread Devin Jeanpierre
Thanks Ben, with your encouragement I have filed http://bugs.python.org/issue23201 -- Devin On Thu, Jan 8, 2015 at 7:03 PM, Ben Finney wrote: > Dave Angel writes: > >> What you don't say is which behavior you actually expected. Since >> 0**0 is undefined mathematically, I'd expect either an ex

Re: Decimals and other numbers

2015-01-08 Thread Ben Finney
Dave Angel writes: > What you don't say is which behavior you actually expected. Since > 0**0 is undefined mathematically, I'd expect either an exception or a > NAN result. Do you think that the ‘int’ and ‘float’ types, which do produce a number result for ‘0 ** 0’, are buggy and should be fixe

Re: Decimals and other numbers

2015-01-08 Thread Devin Jeanpierre
define 0**1, of course. If 0**0 is defined, it must be 1. I Googled around to find a mathematician to back me up, here: http://arxiv.org/abs/math/9205211 (page 6, "ripples"). I expected 1, nan, or an exception, but more importantly, I expected it to be the same for floats and decimals.

Re: Decimals and other numbers

2015-01-08 Thread Chris Rebert
On Thu, Jan 8, 2015 at 6:33 PM, Devin Jeanpierre wrote: > I noticed some very PHP-ish behavior today: > import decimal x = 0 y = float(x) z = decimal.Decimal(x) x == y == z == x > True x ** x > 1 y**y > 1.0 z**z > Traceback (most recent call last): > File

Re: Decimals and other numbers

2015-01-08 Thread Dave Angel
On 01/08/2015 09:33 PM, Devin Jeanpierre wrote: I noticed some very PHP-ish behavior today: import decimal x = 0 y = float(x) z = decimal.Decimal(x) x == y == z == x True x ** x 1 y**y 1.0 z**z Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.7/decimal

Re: Decimals and other numbers

2015-01-08 Thread Ben Finney
Devin Jeanpierre writes: > decimal.InvalidOperation: 0 ** 0 > > I'd file a bug report but I'm anticipating some rational (heh) > explanation. Any ideas? First note that it's explicitly documented as an invalid operation . So someone has at least thought about it and deliberately decided it shoul

Decimals and other numbers

2015-01-08 Thread Devin Jeanpierre
I noticed some very PHP-ish behavior today: >>> import decimal >>> x = 0 >>> y = float(x) >>> z = decimal.Decimal(x) >>> x == y == z == x True >>> x ** x 1 >>> y**y 1.0 >>> z**z Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.7/decimal.py", line 2216, in __pow__

Re: Working with decimals part 2

2014-08-27 Thread Seymore4Head
On Tue, 26 Aug 2014 10:46:56 +1000, alex23 wrote: >On 26/08/2014 3:55 AM, Seymore4Head wrote: >> I changed the program just a little to give myself a little practice >> with number formats. The main thing I wanted to do was make the >> decimal points line up. The problem I am having is with the

Re: Working with decimals part 2

2014-08-25 Thread alex23
On 26/08/2014 3:55 AM, Seymore4Head wrote: I changed the program just a little to give myself a little practice with number formats. The main thing I wanted to do was make the decimal points line up. The problem I am having is with the print (count)(payment)(balance) line. While I don't want

Re: Working with decimals part 2

2014-08-25 Thread MRAB
on. I am not using it, but I am keeping it in. row2 is row4 with: (math.floor(number * 100) / 100, ',.2f') taken out leaving',.2f' For some reason, it is not working. If I try to use row2 I get this error: http://i.imgur.com/FgeF9c9.jpg Most of my learning is trial and erro

Re: Working with decimals part 2

2014-08-25 Thread Mark Lawrence
n formatting. Row4 is the old makeitmoney function. I am not using it, but I am keeping it in. row2 is row4 with: (math.floor(number * 100) / 100, ',.2f') taken out leaving',.2f' For some reason, it is not working. If I try to use row2 I get this error: http://i.img

Re: Working with decimals part 2

2014-08-25 Thread Chris Angelico
On Tue, Aug 26, 2014 at 3:55 AM, Seymore4Head wrote: > For some reason, it is not working. If I try to use row2 I get this > error: > http://i.imgur.com/FgeF9c9.jpg Several meta-issues. Firstly, your subject line talks about 'decimal' again. You're actually working with floats; Python has a qui

Working with decimals part 2

2014-08-25 Thread Seymore4Head
nction. I am not using it, but I am keeping it in. row2 is row4 with: (math.floor(number * 100) / 100, ',.2f') taken out leaving',.2f' For some reason, it is not working. If I try to use row2 I get this error: http://i.imgur.com/FgeF9c9.jpg Most of my learning is trial and

Re: Working with decimals

2014-08-24 Thread Chris Angelico
On Mon, Aug 25, 2014 at 12:51 PM, Steven D'Aprano wrote: > Chris Angelico wrote: > >> I love this list. We can go off on a ridiculously long tangent, simply >> because I said that it's only *usually* best to put imports at the top >> of the file. We all agree that it normally is indeed best to hoi

Re: Working with decimals

2014-08-24 Thread Steven D'Aprano
Chris Angelico wrote: > I love this list. We can go off on a ridiculously long tangent, simply > because I said that it's only *usually* best to put imports at the top > of the file. We all agree that it normally is indeed best to hoist > them, and here we are, arguing over measurement methods on

Re: Working with decimals

2014-08-24 Thread Chris Angelico
On Mon, Aug 25, 2014 at 12:16 PM, Steven D'Aprano wrote: > Joshua Landau wrote: > > > python -c "import sys; print('math' in sys.modules)" >> False >> >> An even easier check: >> > python -c "import time; a = time.time(); import math; b = time.time(); > print(b-a)" >> 0.000601291656494

Re: Working with decimals

2014-08-24 Thread Steven D'Aprano
Joshua Landau wrote: python -c "import sys; print('math' in sys.modules)" > False > > An even easier check: > python -c "import time; a = time.time(); import math; b = time.time(); print(b-a)" > 0.0006012916564941406 > python -c "import math, time; a = time.time(); import m

Re: Working with decimals

2014-08-24 Thread Seymore4Head
On Sun, 24 Aug 2014 14:24:19 -0700, Larry Hudson wrote: >On 08/24/2014 08:12 AM, Seymore4Head wrote: >[snip] >> I almost moved, but I was looking at the print out again for this one: >> print('%3d $%-13.2f $%-14.2f' % (count, payment, balance)) >> >> I can't understand why the $%-13.2f is pushed

Re: Working with decimals

2014-08-24 Thread Larry Hudson
On 08/24/2014 08:12 AM, Seymore4Head wrote: [snip] I almost moved, but I was looking at the print out again for this one: print('%3d $%-13.2f $%-14.2f' % (count, payment, balance)) I can't understand why the $%-13.2f is pushed against the first column, but the $%-14.2f is not. It seems like the

Re: Working with decimals

2014-08-24 Thread Joshua Landau
On 24 August 2014 20:40, Ian Kelly wrote: > That's the same check I posted, just using the in operator instead of a > straight lookup and raising an error. I think I need to take a break from the internet. This is the second time in as many threads that I've responded with what I'm commenting on.

Re: Working with decimals

2014-08-24 Thread Ian Kelly
On Sun, Aug 24, 2014 at 1:29 PM, Joshua Landau wrote: > > On 24 August 2014 20:25, Joshua Landau wrote: > > On 24 August 2014 20:19, Ian Kelly wrote: > >> On Sun, Aug 24, 2014 at 1:17 PM, Ian Kelly wrote: > >>> On Sun, Aug 24, 2014 at 1:12 PM, Joshua Landau wrote: > >>> > Is math not already i

Re: Working with decimals

2014-08-24 Thread Ian Kelly
On Sun, Aug 24, 2014 at 1:25 PM, Joshua Landau wrote: > On 24 August 2014 20:19, Ian Kelly wrote: > > On Sun, Aug 24, 2014 at 1:17 PM, Ian Kelly > wrote: > >> > >> On Sun, Aug 24, 2014 at 1:12 PM, Joshua Landau > wrote: > >> > Is math not already imported by start-up? > >> > >> Why would it be

Re: Working with decimals

2014-08-24 Thread Joshua Landau
On 24 August 2014 20:25, Joshua Landau wrote: > On 24 August 2014 20:19, Ian Kelly wrote: >> On Sun, Aug 24, 2014 at 1:17 PM, Ian Kelly wrote: >>> On Sun, Aug 24, 2014 at 1:12 PM, Joshua Landau wrote: >>> > Is math not already imported by start-up? > > I don't mean into the global namespace, bu

Re: Working with decimals

2014-08-24 Thread Joshua Landau
On 24 August 2014 20:19, Ian Kelly wrote: > On Sun, Aug 24, 2014 at 1:17 PM, Ian Kelly wrote: >> >> On Sun, Aug 24, 2014 at 1:12 PM, Joshua Landau wrote: >> > Is math not already imported by start-up? >> >> Why would it be? > > It's easy to check, by the way: > > $ python -c "import sys; print(s

Re: Working with decimals

2014-08-24 Thread Ian Kelly
On Sun, Aug 24, 2014 at 1:17 PM, Ian Kelly wrote: > > On Sun, Aug 24, 2014 at 1:12 PM, Joshua Landau wrote: > > Is math not already imported by start-up? > > Why would it be? It's easy to check, by the way: $ python -c "import sys; print(sys.modules['math'])" Traceback (most recent call last):

Re: Working with decimals

2014-08-24 Thread Ian Kelly
On Sun, Aug 24, 2014 at 1:12 PM, Joshua Landau wrote: > Is math not already imported by start-up? Why would it be? -- https://mail.python.org/mailman/listinfo/python-list

Re: Working with decimals

2014-08-24 Thread Joshua Landau
On 23 August 2014 23:53, Chris Angelico wrote: > On Sun, Aug 24, 2014 at 8:47 AM, Joshua Landau wrote: >> On 23 August 2014 23:31, Chris Angelico wrote: >>> I'd say "never" is too strong (there are times when it's right to put >>> an import inside a function), but yes, in this case it should rea

Re: Working with decimals

2014-08-24 Thread Seymore4Head
On Sun, 24 Aug 2014 00:04:29 -0700, Larry Hudson wrote: >On 08/23/2014 02:13 PM, Seymore4Head wrote: >> On Sat, 23 Aug 2014 13:47:20 -0400, Seymore4Head >> >> I found this function that I will be saving for later. >> def make_it_money(number): >> import math >> return '$' + str(format(m

Re: Working with decimals

2014-08-24 Thread Seymore4Head
lance, 2 > >print('%3d %13s %14s' % (count, '$' + str(round(payment, 2)), '$' + >str(round(balance, 2 > Thanks for sharing these. I tried every single one. The first two you gave didn't format correctly (as you noted) but it seems like they sho

Re: Working with decimals

2014-08-24 Thread Larry Hudson
On 08/23/2014 02:13 PM, Seymore4Head wrote: On Sat, 23 Aug 2014 13:47:20 -0400, Seymore4Head I found this function that I will be saving for later. def make_it_money(number): import math return '$' + str(format(math.floor(number * 100) / 100, ',.2f')) (I still need more practice to fi

Re: Working with decimals

2014-08-23 Thread Chris Angelico
On Sun, Aug 24, 2014 at 8:47 AM, Joshua Landau wrote: > On 23 August 2014 23:31, Chris Angelico wrote: >> On Sun, Aug 24, 2014 at 7:47 AM, Joshua Landau wrote: >>> So for one "import math" should never go inside a function; you should >>> hoist it to the top of the file with all the other import

Re: Working with decimals

2014-08-23 Thread Joshua Landau
On 23 August 2014 23:31, Chris Angelico wrote: > On Sun, Aug 24, 2014 at 7:47 AM, Joshua Landau wrote: >> So for one "import math" should never go inside a function; you should >> hoist it to the top of the file with all the other imports. > > I'd say "never" is too strong (there are times when i

Re: Working with decimals

2014-08-23 Thread Chris Angelico
On Sun, Aug 24, 2014 at 7:47 AM, Joshua Landau wrote: > So for one "import math" should never go inside a function; you should > hoist it to the top of the file with all the other imports. I'd say "never" is too strong (there are times when it's right to put an import inside a function), but yes,

Re: Working with decimals

2014-08-23 Thread Seymore4Head
tually a good read, although I don't doubt >there are even better resources somewhere: > >https://docs.python.org/3/library/decimal.html > >Note that you probably also want to use the decimal module, seeing as >it's good at storing decimals. > >Final

Re: Working with decimals

2014-08-23 Thread Joshua Landau
On 23 August 2014 22:13, Seymore4Head wrote: > def make_it_money(number): > import math > return ' > + str(format(math.floor(number * 100) / 100, ',.2f')) So for one "import math" should never go inside a function; you should hoist it to the top of the file with all the other imports. Yo

Re: Working with decimals

2014-08-23 Thread Joshua Landau
esources somewhere: https://docs.python.org/3/library/decimal.html Note that you probably also want to use the decimal module, seeing as it's good at storing decimals. Finally, look at "moneyfmt" in the decimal docs: https://docs.python.org/3/library/decimal.html#recipes -- https://

Re: Working with decimals

2014-08-23 Thread Seymore4Head
On Sat, 23 Aug 2014 13:47:20 -0400, Seymore4Head wrote: >I am trying to do this example: >http://openbookproject.net/pybiblio/practice/wilson/loan.php >The instructions warn that floating point math can get messy so I >cheated a little bit to get me going. > >I made my program work by using numbe

Re: Working with decimals

2014-08-23 Thread Mark Lawrence
useful for display, but you would think that there would be enough demand for a built in set of instructions that handle money calculations accurately. The joys of floating point numbers (you're calling them decimals) on computers. Search the archives of this list and you'll fin

Re: Working with decimals

2014-08-23 Thread Seymore4Head
On Sat, 23 Aug 2014 20:24:41 +0100, Mark Lawrence wrote: >On 23/08/2014 20:07, Seymore4Head wrote: >> >> Funny, I though using the web would be better than a book. I don't >> think so anymore. Using the web, it is hard to find square one >> tutorial text. >> > >Try typing something like "python

Re: Working with decimals

2014-08-23 Thread Mark Lawrence
On 23/08/2014 20:07, Seymore4Head wrote: Funny, I though using the web would be better than a book. I don't think so anymore. Using the web, it is hard to find square one tutorial text. Try typing something like "python string formatting tutorial" into your favourite search engine and you'

Re: Working with decimals

2014-08-23 Thread Joel Goldstick
On Sat, Aug 23, 2014 at 3:07 PM, Seymore4Head wrote: > On Sat, 23 Aug 2014 14:21:03 -0400, Joel Goldstick > wrote: > >>On Sat, Aug 23, 2014 at 1:47 PM, Seymore4Head >> wrote: >>> I am trying to do this example: >>> http://openbookproject.net/pybiblio/practice/wilson/loan.php >>> The instructions

Re: Working with decimals

2014-08-23 Thread Seymore4Head
On Sat, 23 Aug 2014 14:21:03 -0400, Joel Goldstick wrote: >On Sat, Aug 23, 2014 at 1:47 PM, Seymore4Head > wrote: >> I am trying to do this example: >> http://openbookproject.net/pybiblio/practice/wilson/loan.php >> The instructions warn that floating point math can get messy so I >> cheated a li

Re: Working with decimals

2014-08-23 Thread Joel Goldstick
On Sat, Aug 23, 2014 at 1:47 PM, Seymore4Head wrote: > I am trying to do this example: > http://openbookproject.net/pybiblio/practice/wilson/loan.php > The instructions warn that floating point math can get messy so I > cheated a little bit to get me going. > > I made my program work by using numb

Working with decimals

2014-08-23 Thread Seymore4Head
I am trying to do this example: http://openbookproject.net/pybiblio/practice/wilson/loan.php The instructions warn that floating point math can get messy so I cheated a little bit to get me going. I made my program work by using numbers that wouldn't get messy. Instead of using 6% interest I used

Re: Missing decimals in the code - some suggestions?

2013-04-17 Thread Ian Kelly
On Wed, Apr 17, 2013 at 12:23 AM, Steven D'Aprano wrote: > On Tue, 16 Apr 2013 12:20:18 -0600, Ian Kelly wrote: > >> This isn't a Python question. If you take a look at the csv file that >> you download from Yahoo, you will see that it only contains 2 digits of >> precision. There's no way to ma

Re: Missing decimals in the code - some suggestions?

2013-04-16 Thread Steven D'Aprano
On Tue, 16 Apr 2013 12:20:18 -0600, Ian Kelly wrote: > This isn't a Python question. If you take a look at the csv file that > you download from Yahoo, you will see that it only contains 2 digits of > precision. There's no way to make Python print out 4 digits of > precision when it is only prov

Re: Missing decimals in the code - some suggestions?

2013-04-16 Thread Terry Jan Reedy
(int(end_date[0:4])) + \ 'g=d&' + \ 'a=%s&' % str(int(start_date[4:6]) - 1) + \ 'b=%s&' % str(int(start_date[6:8])) + \ 'c=%s&' % str(int(start_date[0:4])) + \ 'ignore=.csv' days = urlli

Re: Missing decimals in the code - some suggestions?

2013-04-16 Thread MRAB
(int(end_date[0:4])) + \ 'g=d&' + \ 'a=%s&' % str(int(start_date[4:6]) - 1) + \ 'b=%s&' % str(int(start_date[6:8])) + \ 'c=%s&' % str(int(start_date[0:4])) + \ 'ignore=.csv' days = urlli

Re: Missing decimals in the code - some suggestions?

2013-04-16 Thread Ian Kelly
> 'f=%s&' % str(int(end_date[0:4])) + \ > 'g=d&' + \ > 'a=%s&' % str(int(start_date[4:6]) - 1) + \ > 'b=%s&' % str(int(start_date[6:8])) + \ > 'c=%s&' % str(int(sta

Missing decimals in the code - some suggestions?

2013-04-16 Thread hmjeltevik
'a=%s&' % str(int(start_date[4:6]) - 1) + \ 'b=%s&' % str(int(start_date[6:8])) + \ 'c=%s&' % str(int(start_date[0:4])) + \ 'ignore=.csv' days = urllib.urlopen(url).readlines() data = [day[:-2].split(',

Re: String Formatting Operations for decimals.

2010-04-01 Thread Maxim Lacrima
Hello, Chris! Thanks for your really quick reply! It works! On 1 April 2010 12:14, Chris Rebert wrote: > On Thu, Apr 1, 2010 at 2:08 AM, Lacrima wrote: > > Hello! > > > > I need to format a decimal (floating point) number in the following > > way: > > 10 results in '10' > > 10.5 results in '1

Re: String Formatting Operations for decimals.

2010-04-01 Thread Xavier Ho
Hi Maxim, If it's the trailing zeroes you're concerned about, here's a work-around: >>> ('%.2f' % 10.5678).rstrip('0') '10.57 I'm sure there are better solutions. But this one works for your need, right? Cheers,' Ching-Yun Xavier Ho, Technical Artist Contact Information Mobile: (+61) 04 3335

Re: String Formatting Operations for decimals.

2010-04-01 Thread Chris Rebert
On Thu, Apr 1, 2010 at 2:08 AM, Lacrima wrote: > Hello! > > I need to format a decimal (floating point) number in the following > way: > 10 results in '10' > 10.5 results in '10.5' > 10.50 results in '10.5' > 10.5678 results in 10.57 > > How can I achieve this using standard Python string formatti

String Formatting Operations for decimals.

2010-04-01 Thread Lacrima
Hello! I need to format a decimal (floating point) number in the following way: 10 results in '10' 10.5 results in '10.5' 10.50 results in '10.5' 10.5678 results in 10.57 How can I achieve this using standard Python string formatting operations? Something like '%.2f' works almost as expected: >>>

Re: Binary Decimals in Python

2010-03-30 Thread Mensanator
On Mar 30, 1:52 pm, MRAB wrote: > John Nagle wrote: > > aditya wrote: > >> On Mar 30, 10:49 am, Raymond Hettinger wrote: > >>> On Mar 30, 8:13 am, aditya wrote: > > To get the decimal representation of a binary number, I can just do > this: > int('11',2) # returns 3 > But dec

Re: Binary Decimals in Python

2010-03-30 Thread Chris Kaynor
Chris On Tue, Mar 30, 2010 at 11:14 AM, John Nagle wrote: > aditya wrote: > >> On Mar 30, 10:49 am, Raymond Hettinger wrote: >> >>> On Mar 30, 8:13 am, aditya wrote: >>> >>> To get the decimal representation of a binary number, I can just do this: int('11',2) # returns 3 But d

Re: Binary Decimals in Python

2010-03-30 Thread MRAB
John Nagle wrote: aditya wrote: On Mar 30, 10:49 am, Raymond Hettinger wrote: On Mar 30, 8:13 am, aditya wrote: To get the decimal representation of a binary number, I can just do this: int('11',2) # returns 3 But decimal binary numbers throw a ValueError: int('1.1',2) # should return 1.5,

Re: Binary Decimals in Python

2010-03-30 Thread Grant Edwards
On 2010-03-30, John Nagle wrote: > Hex floats are useful because you can get a string representation of > the exact value of a binary floating point number. It should always > be the case that > >float.fromhex(float.hex(x)) == x Until you try running your program on a machine that repre

Re: Binary Decimals in Python

2010-03-30 Thread Mensanator
On Mar 30, 10:49 am, Raymond Hettinger wrote: > On Mar 30, 8:13 am, aditya wrote: > > > To get the decimal representation of a binary number, I can just do > > this: > > > int('11',2) # returns 3 > > > But decimal binary numbers throw a ValueError: > > > int('1.1',2) # should return 1.5, throws e

Re: Binary Decimals in Python

2010-03-30 Thread John Nagle
aditya wrote: On Mar 30, 10:49 am, Raymond Hettinger wrote: On Mar 30, 8:13 am, aditya wrote: To get the decimal representation of a binary number, I can just do this: int('11',2) # returns 3 But decimal binary numbers throw a ValueError: int('1.1',2) # should return 1.5, throws error instea

Re: Binary Decimals in Python

2010-03-30 Thread Steven D'Aprano
On Tue, 30 Mar 2010 08:28:50 -0700, Patrick Maupin wrote: > On Mar 30, 10:13 am, aditya wrote: >> To get the decimal representation of a binary number, I can just do >> this: >> >> int('11',2) # returns 3 >> >> But decimal binary numbers throw a ValueError: >> >> int('1.1',2) # should return 1.5,

Re: Binary Decimals in Python

2010-03-30 Thread aditya
On Mar 30, 10:49 am, Raymond Hettinger wrote: > On Mar 30, 8:13 am, aditya wrote: > > > To get the decimal representation of a binary number, I can just do > > this: > > > int('11',2) # returns 3 > > > But decimal binary numbers throw a ValueError: > > > int('1.1',2) # should return 1.5, throws e

Re: Binary Decimals in Python

2010-03-30 Thread aditya
On Mar 30, 10:37 am, Benjamin Kaplan wrote: > On Tue, Mar 30, 2010 at 11:13 AM, aditya wrote: > > To get the decimal representation of a binary number, I can just do > > this: > > > int('11',2) # returns 3 > > > But decimal binary numbers throw a ValueError: > > > int('1.1',2) # should return 1.5

Re: Binary Decimals in Python

2010-03-30 Thread MRAB
aditya wrote: To get the decimal representation of a binary number, I can just do this: int('11',2) # returns 3 But decimal binary numbers throw a ValueError: int('1.1',2) # should return 1.5, throws error instead. Is this by design? It seems to me that this is not the correct behavior. int

Re: Binary Decimals in Python

2010-03-30 Thread Grant Olson
Doh! Well the problem is that int's are integers. So yeah, you can't even do that with normal value "int ('2.1')" will also throw an error. And floats don't support radix conversion, because no-one really writes numbers that way. (At least computer programmers...) On 3/30/2010 11:43 AM, Shash

Re: Binary Decimals in Python

2010-03-30 Thread Raymond Hettinger
On Mar 30, 8:13 am, aditya wrote: > To get the decimal representation of a binary number, I can just do > this: > > int('11',2) # returns 3 > > But decimal binary numbers throw a ValueError: > > int('1.1',2) # should return 1.5, throws error instead. > > Is this by design? It seems to me that this

Re: Binary Decimals in Python

2010-03-30 Thread Shashwat Anand
The conversion is not supported for decimal integers AFAIK, however '0b123.456' is always valid. I guess you can always get a decimal number convertor onto Python-recipes On Tue, Mar 30, 2010 at 9:05 PM, Grant Olson wrote: > On 3/30/2010 11:13 AM, aditya wrote: > > To get the decimal represent

Re: Binary Decimals in Python

2010-03-30 Thread Benjamin Kaplan
On Tue, Mar 30, 2010 at 11:13 AM, aditya wrote: > To get the decimal representation of a binary number, I can just do > this: > > int('11',2) # returns 3 > > But decimal binary numbers throw a ValueError: > > int('1.1',2) # should return 1.5, throws error instead. > > Is this by design? It seems t

Re: Binary Decimals in Python

2010-03-30 Thread Grant Olson
On 3/30/2010 11:13 AM, aditya wrote: > To get the decimal representation of a binary number, I can just do > this: > > int('11',2) # returns 3 > > But decimal binary numbers throw a ValueError: > > int('1.1',2) # should return 1.5, throws error instead. > > Is this by design? It seems to me tha

Re: Binary Decimals in Python

2010-03-30 Thread Patrick Maupin
On Mar 30, 10:13 am, aditya wrote: > To get the decimal representation of a binary number, I can just do > this: > > int('11',2) # returns 3 > > But decimal binary numbers throw a ValueError: > > int('1.1',2) # should return 1.5, throws error instead. > > Is this by design? It seems to me that thi

Re: Binary Decimals in Python

2010-03-30 Thread Shashwat Anand
decimal binary number is not included AFAIK On Tue, Mar 30, 2010 at 8:43 PM, aditya wrote: > To get the decimal representation of a binary number, I can just do > this: > > int('11',2) # returns 3 > > But decimal binary numbers throw a ValueError: > > int('1.1',2) # should return 1.5, throws err

Binary Decimals in Python

2010-03-30 Thread aditya
To get the decimal representation of a binary number, I can just do this: int('11',2) # returns 3 But decimal binary numbers throw a ValueError: int('1.1',2) # should return 1.5, throws error instead. Is this by design? It seems to me that this is not the correct behavior. - Aditya -- http://

Re: python decimals

2009-09-16 Thread Andrew Svetlov
Decimal has good enough API and we need to follow it as lot of our code already operates with Decimal. Maybe with different Context and exception types and limited subset of operations - but switching should be not very hard. Decimal arithmetic is good for as. We need to support several types like

Re: python decimals

2009-09-16 Thread Mark Dickinson
On Sep 16, 1:35 am, Andrew Svetlov wrote: > It only reflects the fact what comp.lang.python replicated by several > web sites. > Unfortunately looks like there are no link to library implements that : > ( A few random thoughts: If you just want fixed-precision decimal, there may be simpler solut

Re: python decimals

2009-09-15 Thread Andrew Svetlov
but found nothing. > >> gmpy is interesting project, but supported types is not exactly what > >> we need - rationals and big floats is not decimals in fixed point > >> notation. > >> My team discussed about making own python binding of decNumber - but > >>

Re: python decimals

2009-09-15 Thread Terry Reedy
interesting project, but supported types is not exactly what we need - rationals and big floats is not decimals in fixed point notation. My team discussed about making own python binding of decNumber - but before we start this task I like to ask python community: is there existing implementation? I

Re: python decimals

2009-09-15 Thread Mark Dickinson
found nothing. > gmpy is interesting project, but supported types is not exactly what > we need - rationals and big floats is not decimals in fixed point > notation. > My team discussed about making own python binding of decNumber - but > before we start this task I like to ask python commu

python decimals

2009-09-14 Thread Andrew Svetlov
we need - rationals and big floats is not decimals in fixed point notation. My team discussed about making own python binding of decNumber - but before we start this task I like to ask python community: is there existing implementation? I don't want to invent the wheel again. Thanks. -- http:/

  1   2   >