[Tutor] How to correct decimal addition.
spir
denis.spir at gmail.com
Sun Jan 26 09:09:51 CET 2014
On 01/26/2014 04:22 AM, Keith Winston wrote:
> On Sat, Jan 25, 2014 at 5:09 PM, Oscar Benjamin
> <oscar.j.benjamin at gmail.com> wrote:
>> Perhaps it would be better though to point at this:
>>>>> round(D('0.123456'), 3)
>> Decimal('0.123')
>
> I think you are right. I didn't even think of round(). I think we have
> confounded two issues in this thread, the internal
> representation/accuracy, and the final presentation. They aren't
> really the same thing, unless we force them to be (i.e. using ints).
Yes. Side-note below.
In programming, there is a general confusion between ideas, such as <the number
-1.23> and their representations, like "-1.23" "minus one dot twenty three",
"moins un virgule vingt-trois", "-1,23", or varipus possible strings of bits.
There are outer written or spoken representations (numerals, for numbers) and
internal representations in memory, which we could call "raw data". Raw data are
meaningless (and type-less). Obviously, many truely believe there are data with
meaning or type, that is ideas, *in* a machine; especially many speak and
obviously think as if there were _numbers_ in a computer; as if a machine had a
mind and thought... Numbers and other ideas are only in "heads" of psychical
(mental) living things, as far as we know. there are no numbers, colors, texts,
characters, weapons... in a machine ;-)
The internal representation is no less a representation and a pure convention. 3
can be written
vvvvvv^^
(with, say, bits 'on' and 'off')
it is a pure conventional representation (albeit simple & logical), and works
because routines supposed to operate on numbers take this conventional
representation for granted, both for operations and for input/output conversions
to/from outer written representations.
In both internal and external representations there may be issues related to the
base (eg in python we can also write hex or bin numbers). And a major issue,
that will last as long as CPU's don't process decimal fractionals natively
(so-to-say), is the clash between our expectations related to outer decimals and
the inner processing in binary representation.
d
More information about the Tutor
mailing list