[Curious] Integer division => fraction
Richard A. O'Keefe
ok at cs.otago.ac.nz
Mon Jun 16 02:32:12 UTC 2003
Oca Emilio <eoca at afip.gov.ar> wrote:
> (Why is there no Point>>roundTo: ?)
When drawing in a canvas I use #asIntegerPoint.
which is not the same thing.
Something that caused me some annoyance is:
(Point r: 100 degrees: 30) x =
(Point r: 100 degrees: (180-30) ) negated x
=> true
(Point r: 100 degrees: 60) y = (Point r: 100 degrees: (180-60) ) y
=> false
I see that
(Point r: 100 degrees: 60) - (Point r: 100 degrees: 180-60)
=> 100.0 @ -1.421...e-14
Point r: rho degrees: theta
=> (Point new) setR: rho degrees: theta
=> radians := degrees asFloat degreesToRadians.
x := rho asFloat * radians cos.
y := rho asFloat * radians sin.
The discrepancy boils down to
60 asFloat degreesToRadians sin - 120 asFloat degreesToRadians sin
=> -1.11...e-16
Does Squeak use a math library which uses only a double-precision
approximation to pi? That would account for the magnitude of the
discrepancy.
What's really wanted is an underlying math library where
sinpi(x) returns sin(pi*x) without any scaling by pi, or an Ada-like
y := rho asFloat * (degrees asFloat sin: 360.0)
where the argument of #sin: is the number of units in a full circle.
Even that won't get around the fact that floating-point arithmetic
is imprecise. Do we need any more arguments against 1/3 giving
0.33333333333333333 as the answer?
More information about the Squeak-dev
mailing list
|