Re: Double: 2 Decimal points




"tex" <NoSpam@xxxxxxxxxxx> wrote in message
news:VT5Ie.35$RS.3@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
>> One problem I have with this is that (1.0 / 3.0) + (1.0 / 3.0) + (1.0 /
>> 3.0) and ((1.0 + 1.0 + 1.0)/ 3.0) have a result that differs by 10%, and
>> that my experience is that the compiler doesn't always catch that, and
>> that mainframe programmers don't always think about that.
>
> This has nothing to do w/ integer vs floating pt arithmetic, but rather
> the
> problem is that computers, having finite representations of numbers,
> cannot
> do math correctly, PERIOD! (a x b)/c does not always equal a x (b/c)
> on a computer and this is true regardless of number representation or
> compiler.

This isn't strictly true; some computing environments do calculations in
a symbolic manner instead of numerical (e.g. matlab).

If you declare N = 1, D = 3, and X = N/D, it does not store 0.3333...
into X, but actually stores the equation N/D. If you later multiply X by 3,
it will be able to perform the simplification and store X = N, which gives
the correct result.

- Oliver


.



Relevant Pages

  • OO and information oriented programming (was Re: Simple Parser)
    ... >> If you're developing a compiler for a language for the first time, ... >> the grammar you're using does what you want, ... Computers don't just process for the sake of it. ... reducing complexity, a task at the core of software development. ...
    (comp.programming)
  • Re: OO and information oriented programming (was Re: Simple Parser)
    ... > The parse tree tells the developer a lot about the behaviour of a part of ... The first version of the Basic compiler for my book "Design Your Own ... > Computers don't just process for the sake of it. ... > reducing complexity, a task at the core of software development. ...
    (comp.programming)
  • Re: sprintf
    ... y> never show unpredictable behaviour. ... Computers ... y> heard a DFA generate a true randome number ?? ... It doesn't mean that *any given* compiler will produce ...
    (comp.lang.c)
  • Re: What I can to do with old PL/1 code?
    ... with complex numerical computations and its volume about 10000 lines. ... So, I'm almost completely sure, that that compiler has errors. ... I have several from Island Computers http://www.islandco.com/ ... If this is not for commercial use then you would qualify for a hobbyist license. ...
    (comp.lang.pl1)
  • Re: embedded questions!!!
    ... >> having a compiler that by default stores ... Just because a compiler is not ANSI compliant does not ... >>> I have seen compilers that will store the string in ROM. ...
    (comp.lang.c)