it was just an example where you can "bind" as "late" as possible a combination of symbols with its value... I like late binding :-) in this example allows you to get rigth results... and of course cosPiHalved is not the same as "a/b cos" where a is bound to pi and b to 2... it is not only for literals. On Wed, Jul 8, 2009 at 3:59 PM, Igor Stasenko <siguctua@gmail.com> wrote:
2009/7/8 Hernan Wilkinson <hernan.wilkinson@gmail.com>:
[...] and if you write 1.3, the object that represents that number is not going to be an instance of float but of scaledecimal or fraction or whatever, but not float...
That only solves the issue of representing literals because:
and all operations are made with exact representation.
cannot be done for all operations: obvious ones like square root, log, sin, etc and less obvious ones like #squared where you run out of enough bits to maintain precision (in fixed-width implementations).
not really... root, log, sin, etc could be messages that only inexact numbers know how to answer , so you want "2 sqrt", do "2 asFloat sqrt",
but
for +, *, /, etc. they work as expected. We can also have better representations for number like pi. Why pi is instance of Float and not Pi? If pi is instance of Pi, then cos(pi/2) = 0 could be true... just a quick hack: Pi>>/ aNumber
^ Fraction numerator: self denominator: aNumber "Or maybe an object representing that Pi has been divided/multiplied, etc
Fraction>>cos
^ numerator cosDividedWith: denominator
Pi>>cosDividedWith: denominator
^denominator = 2 ifTrue: [ 0 ] ifFalse: [ ... ]
and so on
don't forget to add Pi>>mantisOfLength: numBits
to compute the Pi up to given precision. :)
But your examples is not about computing a result, but rather predicting it. So why bother writing so much stuff , while you can just implement :
Number>>cosPiHalved ^ 0
:)
R -
_______________________________________________ Pharo-project mailing list Pharo-project@lists.gforge.inria.fr http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
_______________________________________________ Pharo-project mailing list Pharo-project@lists.gforge.inria.fr http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
-- Best regards, Igor Stasenko AKA sig.
_______________________________________________ Pharo-project mailing list Pharo-project@lists.gforge.inria.fr http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project