FAQ

There ought to be severe penalties for idiots that use
floating point dollars for financial applications.
If forced to use floating point (e.g. because customer
demands BASIC), then keep money amounts in whole pennies
(or whatever the smallest currency unit for the country
is), and divide by 100 (or whatever) for printing only (or
just add the decimal point yourself).
In many circumstances this is exactly what you can't do.
The minute you need to calculate percentages you will get in to
the things like .0001254 of a cent, no matter what is you
smallest unit of currency.

I worked for a insurance company (using Business Basic) many
years ago on MAI and Prime gear, and we did everything as floats
with 14 places after the decimal point,and only rounded when
a human needed to see a number, and then used standard accounting
practices for rounding,

Rgds

Tim
OK, so don't use whole pennies (or smallest currency) as your
base, use 10,000ths of a penny, but still use integer arithmetic
for your calculations.

Floating point has too many rounding errors to be trustworthy;
or, looking at it from another angle, floating-point calculations
cannot be 100% accurate because of the way it's implemented.

-gustavo




Advertencia:
La informacion contenida en este mensaje es confidencial y restringida y
esta destinada unicamente para el uso de la persona arriba indicada, Esta
comunicacion representa la opinion personal del remitente y no refleja
necesariamente la opinion de la Compa?ia. Se le notifica que esta
estrictamente prohibida cualquier difusion, distribucion o copia de este
mensaje. Si ha recibido esta comunicacion o copia de este mensaje por error,
o si hay problemas en la transmision, favor de comunicarse con el remitente.


Todo el correo electr?nico enviado para o desde esta direcci?n ser?
procesado por el sistema de correo corporativo de HEB. Tal correo
electr?nico esta sujeto a ser almacenado y puede ser revisado por alguien
ajeno al recipiente autorizado con el prop?sito de monitorear que se cumplan
las normas de seguridad de la empresa.

Search Discussions

  • Delaney, Timothy at Sep 25, 2002 at 11:50 pm

    From: danb_83 at yahoo.com [mailto:danb_83 at yahoo.com]

    "Stuart D. Gathman" <stuart at bmsi.com> wrote in message
    news:<amo0aq$5nf$1 at nntp2-cm.news.eni.net>...
    ...
    There ought to be severe penalties for idiots that use
    floating point
    dollars for financial applications. If forced to use floating point
    (e.g. because customer demands BASIC), then keep money amounts in
    whole pennies (or whatever the smallest currency unit for
    the country
    is), and divide by 100 (or whatever) for printing only (or
    just add the
    decimal point yourself).
    That's exactly how things were done at my old workplace, except that
    cents were also used for user input. Most of the time.
    It's called Fixed Point arithmetic, and strangely enough, Tim Peters wrote
    an excellent implementation ...

    Tim Delaney
  • Sismex01 at Sep 30, 2002 at 5:59 pm

    Steve Holden wrote:
    <sismex01 at hebmex.com> wrote...


    [ ... ]
    OK, so don't use whole pennies (or smallest currency) as your
    base, use 10,000ths of a penny, but still use integer arithmetic
    for your calculations.
    Normal Integers aren't big enough. 2^31 / 10K == 215K.

    --jb

    --
    James J. Besemer 503-280-0838 voice
    2727 NE Skidmore St. 503-280-0375 fax
    Portland, Oregon 97211-6557 mailto:jb at cascade-sys.com
    http://cascade-sys.com
    "Integer arithmetic" != "32-bit integer arithmetic". The first
    may be based on the second but they are definitely not the
    same thing. Python longs are memory-limited, yet they
    are also based on machine integers. Does that make them
    unsuitable?

    -gustavo










    Advertencia:
    La informacion contenida en este mensaje es confidencial y restringida y
    esta destinada unicamente para el uso de la persona arriba indicada, Esta
    comunicacion representa la opinion personal del remitente y no refleja
    necesariamente la opinion de la Compa?ia. Se le notifica que esta
    estrictamente prohibida cualquier difusion, distribucion o copia de este
    mensaje. Si ha recibido esta comunicacion o copia de este mensaje por error,
    o si hay problemas en la transmision, favor de comunicarse con el remitente.


    Todo el correo electr?nico enviado para o desde esta direcci?n ser?
    procesado por el sistema de correo corporativo de HEB. Tal correo
    electr?nico esta sujeto a ser almacenado y puede ser revisado por alguien
    ajeno al recipiente autorizado con el prop?sito de monitorear que se cumplan
    las normas de seguridad de la empresa.
  • James J. Besemer at Oct 1, 2002 at 9:22 am

    sismex01 at hebmex.com wrote:
    "Integer arithmetic" != "32-bit integer arithmetic".
    I never said it was. I made a true assertion about "normal integers,"
    meaning the native machine word size on most machines.
    Python longs are memory-limited, yet they
    are also based on machine integers. Does that make them
    unsuitable?
    I know. I never said they weren't.

    But Steve said "integers' NOT "Python longs" and my only point was that
    Steve's original suggestion (as stated) was not practical with most
    machine's native integers.

    And I'll add that if you're going to consider Longs you may as well go
    with FixedPoint and do it "right". ;o)

    --jb

    --
    James J. Besemer 503-280-0838 voice
    2727 NE Skidmore St. 503-280-0375 fax
    Portland, Oregon 97211-6557 mailto:jb at cascade-sys.com
    http://cascade-sys.com
  • Steve Holden at Oct 1, 2002 at 4:21 pm
    "James J. Besemer" <jb at cascade-sys.com> wrote in message
    news:mailman.1033464184.26508.python-list at python.org...
    sismex01 at hebmex.com wrote:
    "Integer arithmetic" != "32-bit integer arithmetic".
    I never said it was. I made a true assertion about "normal integers,"
    meaning the native machine word size on most machines.
    Python longs are memory-limited, yet they
    are also based on machine integers. Does that make them
    unsuitable?
    I know. I never said they weren't.

    But Steve said "integers' NOT "Python longs" and my only point was that
    Steve's original suggestion (as stated) was not practical with most
    machine's native integers.
    I never said that, as I have already pointed out. It was Outlook Express'
    weird quoting, which in that post I failed to correct, that made it look
    like me.

    Be that as it may, if that was your only point you'd do well to stop
    hammering it now everyone's heard you.
    And I'll add that if you're going to consider Longs you may as well go
    with FixedPoint and do it "right". ;o)
    regards
    -----------------------------------------------------------------------
    Steve Holden http://www.holdenweb.com/
    Python Web Programming http://pydish.holdenweb.com/pwp/
    Previous .sig file retired to www.homeforoldsigs.com
    -----------------------------------------------------------------------
  • Delaney, Timothy at Oct 2, 2002 at 5:23 am

    From: Dennis Lee Bieber [mailto:wlfraed at ix.netcom.com]

    When I took science classes, I'd have been dinged a
    few points if I
    turned in 0.035 -- the rule was to report results to the same
    significance as the inputs.
    Yes - but the point there is that there is error in the inputs.

    The point of all this is that we are dealing with *exact* inputs ... and
    ending up with error.

    Tim Delaney
  • Cameron Laird at Oct 15, 2002 at 12:23 am
    In article <mailman.1032997934.805.python-list at python.org>,
    Delaney, Timothy wrote:
    .
    .
    .
    It's called Fixed Point arithmetic, and strangely enough, Tim Peters wrote
    an excellent implementation ...

    Tim Delaney
    Someone who wants to pursue this, and likes the motivation
    of a change to improve on the timbot, might consider a
    Pythonic implementation of so-called "adaptive integers"
    <URL: http://wiki.tcl.tk/4329 >. For a useful range of
    data, these occupy *less* space than "normal" computer-
    encoded numbers, and exhibit precision limited only by
    available memory.

    The URL above gives the most straightforward implementation.
    Myself, I like a variant which encodes rational arithmetic ...
    --

    Cameron Laird <Cameron at Lairds.com>
    Business: http://www.Phaseit.net
    Personal: http://phaseit.net/claird/home.html

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedSep 25, '02 at 2:00p
activeOct 15, '02 at 12:23a
posts7
users5
websitepython.org

People

Translate

site design / logo © 2022 Grokbase