"trans.  (T. Onoma)" <transami / runbox.com> writes:

> Everyone, obviously, has their own particular perspective on the
> world. You have yours, and it has been colored by your experiences,
> including your Introduction to Computer Programming course in
> 1969. That's good. But mine is quite different. And I think people
> should respect differences. You plainly infer that I am uneducated and
> hence, if I were, would not have a) made such joke and b) made other
> assertions. Such things are relative. I could say for instance that
> the foundations of geometry are fundamental to modern mathematics and
> hence likewise to programming, and that you have no right to write a
> single line of code until you've worked every proof of all 13 books of
> Euclid's Elements (as I have). I'm sure many others could fill in the
> blanks here with their own experiences. But that's not fair --to any
> of us.
>
> I'm not claiming to be a mathematical expert. I have a fair grasp of
> many concepts including floating-point arithmetic --but it's certainly
> not perfect. I simply _believe_ that it can be done. That's my
> opinion, I may be wrong, but I may also be right. You can have your
> opinion as well. But please do not belittle my _attempt_. At least I'm
> trying a better world. An introductory Computer Programming course in
> 1969 is certainly not the last word on such matters.
>
> T.

The "better world" you are talking about already exists.  I will explain
that point below.

People who understand the concepts of fixed-point and floating-point
arithmetic would not expect the "to_i" operator to do _rounding_.  That
operation is defined as one which performs _truncation_.  People who
never learned these numerical concepts or who incorrectly expect
truncation operators to do rounding should not be writing code to handle
the navigation of Mars landers.

If someone wants the two floating-point numbers 100.00 and 9.95 to be
multiplied together to yield the integer result 995, then rounding will
_have to_ be performed.  In order to do that, different procedures,
other than (100.00 * 9.95).to_i, need to be used.  For example, one of
many ways to do it is this:

  irb(main):001:0> sprintf('%.0f', 100.00 * 9.95).to_i
  => 995

That's because the "%f" format for sprintf is _defined_ as specifying
that rounding gets done when it converts a floating-point number to its
string representation.  The to_i operator alone is not defined in that
way.

There are other algorithms and packages that already are in existence
that will also perform rounding.  In other words, we already live in
this "better world".  Someone who needs to use representations of
decimal numbers that are forced into a fixed precision should learn that
these various algorithms and packages exist, and they should learn how
to make use of them.

For example, see the "mathx" package in RAA.  Also, see the BigDecimal
and Rational packages, which already have been mentioned in this
thread, I believe.


-- 
 Lloyd Zusman
 ljz / asfast.com
 God bless you.