Discussion:
Unspecified Behaviour
(too old to reply)
Brian Attwell
2010-05-23 01:49:20 UTC
Permalink
To what degree do we need our programs to mimic the unspecified behaviour in
provided executables?

For example, running PreciseMoney.out on linux006.student.cs:
command: $1.999951
== $2.00

command: $1.999949
== $1.99

This behavior occurs predictably in PreciseMoney.out and can be easily
reverse engineered. However, is it something that we are responsible for
doing? Or, should we never need to implement behaviour in provided
executables unless they are mentioned in the assignment.
Joanne Atlee
2010-05-23 15:25:53 UTC
Permalink
Post by Brian Attwell
To what degree do we need our programs to mimic the unspecified behaviour in
provided executables?
command: $1.999951
== $2.00
command: $1.999949
== $1.99
This behavior occurs predictably in PreciseMoney.out and can be easily
reverse engineered. However, is it something that we are responsible for
doing? Or, should we never need to implement behaviour in provided
executables unless they are mentioned in the assignment.
Unfortunately, there is no perfect solution to this problem (at least
not without changing the interface of the Money ADT to remove all inputs
and outputs of floating-point type). The problem is with the innate
imprecision of floating point numbers.

As indicated in the original mea culpa new posting, you should keep your
inputs (both Money value inputs and multiplication factors) to at most
two decimal places.


Jo


P.S. For those who want to know more about floating-point number
representations, see the following (long!) explanation. Or take CS 370.

http://docs.sun.com/source/806-3568/ncg_goldberg.html

Loading...