Re: python rounding problem.

2006-05-13 Thread Florian Diesch
Thomas Bartkus [EMAIL PROTECTED] wrote:

 Grant Edwards [EMAIL PROTECTED] wrote in message
 news:[EMAIL PROTECTED]
 On 2006-05-08, Thomas Bartkus [EMAIL PROTECTED] wrote:

  does python support true rations, which means that 1/3 is a
  true one-third and not 0.3 rounded off at some
  arbitrary precision?
 
  At risk of being boring  ;-)
 
  - Python supports both rational and irrational numbers as
floating point numbers the way any language on any digital
computer does - imprecisely.
 
  A true (1/3) can only be expressed as a fraction.

 At the risk of being both boring and overly pedantic, that's
 not true.  In base 3, the value in question is precisely
 representable in floating point: 0.1

  As soon as you express it as a floating point - you are in a
  bit of trouble because that's impossible.

 It's not possible in base 2 or base 10.  It's perfectly
 possible in base 9 (used by the Nenets of Northern Russia) base
 12 (popular on planets where everybody has twelve toes) or base
 60 (used by th Sumerians).  [I don't know if any of those
 peoples used floating point in those bases -- I'm just pointing
 out that your prejudice towards base 10 notation is showing.]

  You can not express (1/3) as a floating point in Python any
  more than you can do it with pencil and paper.

 That's true assuming base 2 in Python and base 10 on paper. The
 base used by Python is pretty much etched in stone (silicon, to
 be precise).  There used to be articles about people working on
 base-3 logic gates, but base-3 logic never made it out of the
 lab. However, you can pick any base you want when using paper
 and pencil.

  You can be precise and write 1/3 or you can surrender to
  arithmetic convenience and settle for the imprecise by writing
  0.3, chopping it off at some arbitrary precision.

 Or you can write  0.1
  3

 :)

 Ahhh!
 But if I need to store the value 1/10 (decimal!), what kind of a precision
 pickle will I then find myself while working in base 3 ?  How much better
 for precision if we just learn our fractions and stick to storing integer
 numerators alongside integer denominators in big 128 bit double registers ?

 Even the Nenets might become more computationally precise by such means ;-)
 And how does a human culture come to decide on base 9 arithmetic anyway?

Just guessing: 
 * Use one thumb to point at one of the other 9 fingers
 * Every finger (except for the thumb) has 3 segments (and links), each
   of which can easily divided in three part (upper, middle, lower or left
   middle, right for the links) making 9 points for each finger.


 Even base 60 makes more sense if you like it when a lot of divisions come
 out nice and even.

You can count to 60 using two hands: Use the right thumb to point on
one of the 12 segments of the remaining 4 fingers and on the left hand
one finger for each dozen.


Of course this is wasting resources as you can count to 1023 with your
fingers. I never heard of a culture doing so, though.



   Florian
-- 
http://www.florian-diesch.de/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python rounding problem.

2006-05-11 Thread Tim Roberts
chun ping wang [EMAIL PROTECTED] wrote:

Hey i have a stupid question.

How do i get python to print the result in only three decimal place...

Example round (2.9954254, 3)
2.9951

but i want to get rid of all trailing 0's..how would i do that?

Your problem is not a problem in real programs -- it's only a problem
because of the way the interactive interpreter works:

C:\WINDOWSpython
Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)] on
win32
Type help, copyright, credits or license for more information.
 round(2.99543322,3)
2.9951
 print round(2.99543322,3)
2.995


-- 
- Tim Roberts, [EMAIL PROTECTED]
  Providenza  Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python rounding problem.

2006-05-09 Thread Thomas Bartkus
Grant Edwards [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 On 2006-05-08, Thomas Bartkus [EMAIL PROTECTED] wrote:

  Or you can write  0.1
   3
 
  :)
 
  Ahhh!
 
  But if I need to store the value 1/10 (decimal!), what kind of
  a precision pickle will I then find myself while working in
  base 3?

 Then we're right back where we started.  No matter what base
 you choose, any fixed length floating-point representation can
 only represent 0% of all rational numbers.

 So, clearly what we need are floating point objects with
 configurable bases -- bases that automatically adjust to
 maintain exact representation of calculation results.  Which
 probably exactly the same as just storing rational numbers as
 numerator,denominator tuples as you suggest.

  How much better for precision if we just learn our fractions
  and stick to storing integer numerators alongside integer
  denominators in big 128 bit double registers ?

I completely overlooked the infinite (presumably!) length integer handling
in Python.  You can do integer arithmetic on integers of large and arbitrary
lengths and if ultimate precision were indeed so important (and I can't
imagine why!) then working with numerators and denominators stored as tuples
is quite practical.

Anyone old enough to remember Forth might remember the arguments about how
unnecessary floating point is.  True enough!  Floating point is merely a
convenience for which we sacrifice some (insignificant!) arithmetic
precision to enjoy.

  Even the Nenets might become more computationally precise by
  such means ;-) And how does a human culture come to decide on
  base 9 arithmetic anyway?

 I've no clue, whatsoever.  I just stumbled across that factoid
 when I used Wikipedia to look up which civilizations used
 base-60.  For some reason I can never remember whether it was
 one of the mesoamerican ones or one of the mesopotamian ones.

I suspect a hoax or an urban legend here.  A brief and casual googling
brings up the Nenets but no mention of base 9 arithmetic which I would find
rather astonishing.
Look up the Tasaday tribe together with the word hoax.  A great joke on
academic anthropologists really.

On the other hand, the name Nenet is full of Ns and so evocative of the
number nine ;-)

  Even base 60 makes more sense if you like it when a lot of
  divisions come out nice and even.

 Did they actually have 60 unique number symbols and use
 place-weighting in a manner similar to the arabic/indian system
 we use?

I don't know.
I do know that we have 360 degrees in a circle for the simple reason that
this is evenly divisible by so damned many integers.  A significant and
logical convenience if you have to do all your calculations on a wooden
board using the chunk of charcoal you hold in your fist.

Thomas Bartkus

  Do the Nenets amputate the left pinky as a rite of adulthood
  ;-)

 Nah, winters up there are so friggin' cold that nobody ever has
 more than nine digits by the time they reach adulthood.

 -- 
 Grant Edwards   grante Yow!  Hello. Just walk
   at   along and try NOT to
think
visi.comabout your INTESTINES
being
almost FORTY YARDS
LONG!!


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python rounding problem.

2006-05-09 Thread Grant Edwards
On 2006-05-09, Thomas Bartkus [EMAIL PROTECTED] wrote:

 Even base 60 makes more sense if you like it when a lot of
 divisions come out nice and even.

 Did they actually have 60 unique number symbols and use
 place-weighting in a manner similar to the arabic/indian
 system we use?

 I don't know.

I googled around a while last night, and they ahd sort of a
hybrid notation.  The Sumerians started withindividual tic
marks up to 9, and symbols for 10, 60, 600, 3600 and so on.
That evolved into the Babylonian base-60 position-weighted
system (without a zero symbol) that used only the 1 symbol and
the 10 symbol.

http://it.stlawu.edu/%7Edmelvill/mesomath/sumerian.html
http://www.ancientscripts.com/sumerian.html
http://www-gap.dcs.st-and.ac.uk/~history/HistTopics/Babylonian_numerals.html

 I do know that we have 360 degrees in a circle

And 60 seconds in a minute, 60 minutes in a hour (for both time
and angles), and 60 minutes in a degree.

-- 
Grant Edwards   grante Yow!  PARDON me, am I
  at   speaking ENGLISH?
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python rounding problem.

2006-05-09 Thread Dan Bishop
Grant Edwards wrote:
...
 Did they actually have 60 unique number symbols and use
 place-weighting in a manner similar to the arabic/indian system
 we use?

The Bablyonians did use a place-value system, but they only had two
basic numerals: a Y-like symbol for 1 and a -like symbol for ten.
These were combined to make base-60 digits.  For example, 59 was
represented by

 YYY
YYY
YYY

Zero (used as a placeholder, but not as a number in itself) was
represented by a space.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python rounding problem.

2006-05-09 Thread Grant Edwards
On 2006-05-09, Dan Bishop [EMAIL PROTECTED] wrote:
 Grant Edwards wrote:
 ...
 Did they actually have 60 unique number symbols and use
 place-weighting in a manner similar to the arabic/indian system
 we use?

 The Bablyonians did use a place-value system, but they only had two
 basic numerals: a Y-like symbol for 1 and a -like symbol for ten.
 These were combined to make base-60 digits.  For example, 59 was
 represented by

 YYY
YYY
YYY

 Zero (used as a placeholder, but not as a number in itself) was
 represented by a space.

And they also (acording to the web pages I found) used base-60
floating point notation, but without an actual symbol to
represent the sexagesimal point.  Which seems really ambiguous --
even to somebody who does know how to use a slide rule.

-- 
Grant Edwards   grante Yow!  I'm totally
  at   DESPONDENT over the LIBYAN
   visi.comsituation and the price
   of CHICKEN...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python rounding problem.

2006-05-09 Thread Dan Bishop
Grant Edwards wrote:
 On 2006-05-09, Dan Bishop [EMAIL PROTECTED] wrote:
  Grant Edwards wrote:
  ...
  Did they actually have 60 unique number symbols and use
  place-weighting in a manner similar to the arabic/indian system
  we use?
 
  The Bablyonians did use a place-value system, but they only had two
  basic numerals: a Y-like symbol for 1 and a -like symbol for ten.
  These were combined to make base-60 digits.  For example, 59 was
  represented by
 
  YYY
 YYY
 YYY
 
  Zero (used as a placeholder, but not as a number in itself) was
  represented by a space.

 And they also (acording to the web pages I found) used base-60
 floating point notation, but without an actual symbol to
 represent the sexagesimal point.  Which seems really ambiguous --
 even to somebody who does know how to use a slide rule.

Yes, it was.  (Our spy's message says that Cyrus the Great has '6 '
troops.  Does that mean 360 or 21,600?)

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python rounding problem.

2006-05-08 Thread Thomas Bartkus
Gary Wessle [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 Erik Max Francis [EMAIL PROTECTED] writes:

  chun ping wang wrote:
 
   Hey i have a stupid question.
   How do i get python to print the result in only three decimal
   place...
   Example round (2.9954254, 3)
   2.9951
   but i want to get rid of all trailing 0's..how would i do that?
 
  Floating point arithmetic is inherently imprecise.  This is not a
  Python problem.

 does python support true rations, which means that 1/3 is a true
 one-third and not 0.3 rounded off at some arbitrary precision?

At risk of being boring  ;-)

- Python supports both rational and irrational numbers as floating point
numbers the way any language on any digital computer does - imprecisely.

A true (1/3) can only be expressed as a fraction. As soon as you express
it as a floating point - you are in a bit of trouble because that's
impossible.  You can not express (1/3) as a floating point in Python any
more than you can do it with pencil and paper.  You can be precise and write
1/3 or you can surrender to arithmetic convenience and settle for the
imprecise by writing 0.3, chopping it off at some arbitrary
precision.

Which is exactly what you did in your post ;-)
Thomas Bartkus


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python rounding problem.

2006-05-08 Thread Grant Edwards
On 2006-05-08, Thomas Bartkus [EMAIL PROTECTED] wrote:

 does python support true rations, which means that 1/3 is a
 true one-third and not 0.3 rounded off at some
 arbitrary precision?

 At risk of being boring  ;-)

 - Python supports both rational and irrational numbers as
   floating point numbers the way any language on any digital
   computer does - imprecisely.

 A true (1/3) can only be expressed as a fraction.

At the risk of being both boring and overly pedantic, that's
not true.  In base 3, the value in question is precisely
representable in floating point: 0.1

 As soon as you express it as a floating point - you are in a
 bit of trouble because that's impossible.

It's not possible in base 2 or base 10.  It's perfectly
possible in base 9 (used by the Nenets of Northern Russia) base
12 (popular on planets where everybody has twelve toes) or base
60 (used by th Sumerians).  [I don't know if any of those
peoples used floating point in those bases -- I'm just pointing
out that your prejudice towards base 10 notation is showing.]

 You can not express (1/3) as a floating point in Python any
 more than you can do it with pencil and paper.

That's true assuming base 2 in Python and base 10 on paper. The
base used by Python is pretty much etched in stone (silicon, to
be precise).  There used to be articles about people working on
base-3 logic gates, but base-3 logic never made it out of the
lab. However, you can pick any base you want when using paper
and pencil. 

 You can be precise and write 1/3 or you can surrender to
 arithmetic convenience and settle for the imprecise by writing
 0.3, chopping it off at some arbitrary precision.

Or you can write  0.1
 3

:)

-- 
Grant Edwards   grante Yow!  Yes, Private
  at   DOBERMAN!!
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python rounding problem.

2006-05-08 Thread Thomas Bartkus
Grant Edwards [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 On 2006-05-08, Thomas Bartkus [EMAIL PROTECTED] wrote:

  does python support true rations, which means that 1/3 is a
  true one-third and not 0.3 rounded off at some
  arbitrary precision?
 
  At risk of being boring  ;-)
 
  - Python supports both rational and irrational numbers as
floating point numbers the way any language on any digital
computer does - imprecisely.
 
  A true (1/3) can only be expressed as a fraction.

 At the risk of being both boring and overly pedantic, that's
 not true.  In base 3, the value in question is precisely
 representable in floating point: 0.1

  As soon as you express it as a floating point - you are in a
  bit of trouble because that's impossible.

 It's not possible in base 2 or base 10.  It's perfectly
 possible in base 9 (used by the Nenets of Northern Russia) base
 12 (popular on planets where everybody has twelve toes) or base
 60 (used by th Sumerians).  [I don't know if any of those
 peoples used floating point in those bases -- I'm just pointing
 out that your prejudice towards base 10 notation is showing.]

  You can not express (1/3) as a floating point in Python any
  more than you can do it with pencil and paper.

 That's true assuming base 2 in Python and base 10 on paper. The
 base used by Python is pretty much etched in stone (silicon, to
 be precise).  There used to be articles about people working on
 base-3 logic gates, but base-3 logic never made it out of the
 lab. However, you can pick any base you want when using paper
 and pencil.

  You can be precise and write 1/3 or you can surrender to
  arithmetic convenience and settle for the imprecise by writing
  0.3, chopping it off at some arbitrary precision.

 Or you can write  0.1
  3

 :)

Ahhh!
But if I need to store the value 1/10 (decimal!), what kind of a precision
pickle will I then find myself while working in base 3 ?  How much better
for precision if we just learn our fractions and stick to storing integer
numerators alongside integer denominators in big 128 bit double registers ?

Even the Nenets might become more computationally precise by such means ;-)
And how does a human culture come to decide on base 9 arithmetic anyway?
Even base 60 makes more sense if you like it when a lot of divisions come
out nice and even.

Do the Nenets amputate the left pinky as a rite of adulthood ;-)
Thomas Bartkus




-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python rounding problem.

2006-05-08 Thread Grant Edwards
On 2006-05-08, Thomas Bartkus [EMAIL PROTECTED] wrote:

 Or you can write  0.1
  3

 :)

 Ahhh!

 But if I need to store the value 1/10 (decimal!), what kind of
 a precision pickle will I then find myself while working in
 base 3?

Then we're right back where we started.  No matter what base
you choose, any fixed length floating-point representation can
only represent 0% of all rational numbers.

So, clearly what we need are floating point objects with
configurable bases -- bases that automatically adjust to
maintain exact representation of calculation results.  Which
probably exactly the same as just storing rational numbers as
numerator,denominator tuples as you suggest.

 How much better for precision if we just learn our fractions
 and stick to storing integer numerators alongside integer
 denominators in big 128 bit double registers ?

 Even the Nenets might become more computationally precise by
 such means ;-) And how does a human culture come to decide on
 base 9 arithmetic anyway?

I've no clue, whatsoever.  I just stumbled across that factoid
when I used Wikipedia to look up which civilizations used
base-60.  For some reason I can never remember whether it was
one of the mesoamerican ones or one of the mesopotamian ones.

 Even base 60 makes more sense if you like it when a lot of
 divisions come out nice and even.

Did they actually have 60 unique number symbols and use
place-weighting in a manner similar to the arabic/indian system
we use?

 Do the Nenets amputate the left pinky as a rite of adulthood
 ;-)

Nah, winters up there are so friggin' cold that nobody ever has
more than nine digits by the time they reach adulthood.

-- 
Grant Edwards   grante Yow!  Hello. Just walk
  at   along and try NOT to think
   visi.comabout your INTESTINES being
   almost FORTY YARDS LONG!!
-- 
http://mail.python.org/mailman/listinfo/python-list


python rounding problem.

2006-05-07 Thread chun ping wang
Hey i have a stupid question.

How do i get python to print the result in only three decimal place...

Example round (2.9954254, 3)
2.9951

but i want to get rid of all trailing 0's..how would i do that?

_
Express yourself instantly with MSN Messenger! Download today - it's FREE! 
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python rounding problem.

2006-05-07 Thread Erik Max Francis
chun ping wang wrote:

 Hey i have a stupid question.
 
 How do i get python to print the result in only three decimal place...
 
 Example round (2.9954254, 3)
 2.9951
 
 but i want to get rid of all trailing 0's..how would i do that?

Floating point arithmetic is inherently imprecise.  This is not a Python 
problem.

If you want to print it to only three digits, then use something like::

  '%.3f' % 2.9954254
'2.995'

-- 
Erik Max Francis  [EMAIL PROTECTED]  http://www.alcyone.com/max/
San Jose, CA, USA  37 20 N 121 53 W  AIM erikmaxfrancis
   Whoever contends with the great sheds his own blood.
   -- Sa'di
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python rounding problem.

2006-05-07 Thread gene tani

Erik Max Francis wrote:
 chun ping wang wrote:

  Hey i have a stupid question.
 
  How do i get python to print the result in only three decimal place...
 
  Example round (2.9954254, 3)
  2.9951
 
  but i want to get rid of all trailing 0's..how would i do that?

 Floating point arithmetic is inherently imprecise.  This is not a Python
 problem.
 

http://www2.hursley.ibm.com/decimal/
(read about IEEE754 here)

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python rounding problem.

2006-05-07 Thread Gary Wessle
Erik Max Francis [EMAIL PROTECTED] writes:

 chun ping wang wrote:
 
  Hey i have a stupid question.
  How do i get python to print the result in only three decimal
  place...
  Example round (2.9954254, 3)
  2.9951
  but i want to get rid of all trailing 0's..how would i do that?
 
 Floating point arithmetic is inherently imprecise.  This is not a
 Python problem.

does python support true rations, which means that 1/3 is a true
one-third and not 0.3 rounded off at some arbitrary precision?

-- 
http://mail.python.org/mailman/listinfo/python-list