MOO-cows Mailing List Archive

[Prev][Next][Index][Thread]

Re: floating point support (was Re: suspend())



In article <SPAM> Roger Crew  <rfc@microsoft.com> wrote:
> 
> Whatever you do, please do *NOT* put in implicit coercions.  
> For example, in
>
>  a = 5.0;
>  b = 3;
>  c = a / b;
>
> the third line should be throwing an error.  It may seem convenient to have
> an implicit coercion in there, but in the long run this will lead to 
> error-prone code with truncations silently occurring where you least
> expect them. 
>
> People seem to have this idea that, because integers can be viewed as
> a subSET of the reals, that integers, as a datatype, should be a
> subTYPE of the real/float datatype, and it just ain't so... (capsule
> summary: it's not the sets of elements that matters so much as the
> sets of OPERATIONS that you want to be able to use; sin is not a
> sensible operation to use on integers ($trig_utils notwithstanding),
> nor is % a sensible operation to use on floats; end of story).

I disagree.  I think implicit promotions are very useful.  Implicit
*demotions* are not.  % is a perfectly sensible operation on floats
(returning a floating-point number, e.g. 5.5 % 3 == 2.5).

	-hpa
-- 
PGP public key available - finger hpa@terminus.storm.net
"The earth is but one country, and mankind its citizens."  --  Bahá'u'lláh
GE/CS 3.1 d- s-:- a- C++++ ULIS++++$ P+++ L++++>+++++ E++ W++ N++ o+ K
w--- O@ M V- PGP+ t+ 5++ X? R@ tv- b++ DI++++ D++(+) G e++ h- r-- y-


Follow-Ups: References:

Home | Subject Index | Thread Index