[M3devel] FloatMode
Randy Coleburn
rcolebur at SCIRES.COM
Tue Jan 12 06:18:51 CET 2010
Jay,
I think the documented intent in Modula-3 is that the programmer should write his code under the premise that any operation that could produce an overflow should be rewritten so as to avoid that problem. Further, that the implementation may or may not actually check for this condition, but to rely on it working a certain way (e.g., silent wrap) would be wrong. Further, if FloatMode were implemented, it would be possible to force the overflow check on.
This situation does not prohibit a programmer from writing something that could produce overflow, and the fact that on some implementations overflow is not checked is considered ok for performance reasons. It is just that if the programmer were to rely on silent wrap, this reliance is NOT supported by the language and at some point will probably cause a checked runtime error.
Indeed, folks often turn on extra checking during program testing to find as many programming faults as possible, then turn off the extra checking for production/delivery code to gain performance. So Modula-3 as a language supports this concept, though not all implementations may provide the ability to turn certain checks on or off.
I agree that lumping the integer overflow control into an interface named "FloatMode" makes it a bit hard to find since "FloatMode" would make one think that the interface deals only with floating point.
So, in Modula-3 a good programmer will add appropriate logic to prevent overflow by explicitly coding wrap-around or using some other method appropriate to the task at hand. A sloppy programmer won't care and his code will eventually break. See the comments about long-lived readers/writers for an example.
Regards,
Randy
From: jayk123 at hotmail.com [mailto:jayk123 at hotmail.com] On Behalf Of Jay K
Sent: Monday, January 11, 2010 11:55 PM
To: Tony; m3devel
Subject: [M3devel] FloatMode
I thought FloatMode was only related to floating point.
So I looked:
"IntOverflow" = an integer operation produced a result whose
absolute value is too large to be represented.
"IntDivByZero" = integer "DIV" or "MOD" by zero.
\end{quote}
This part of it should be easy to implement for all architectures.
The entire thing probably isn't too difficult either on many platforms either.
However...I was surprised by this.
I thought the real "intent" in Modula-3 to not have this be configurable
and endeavor for overflow and divide by zero to always immediately
raise an exception? The only "out" is that it might not get implemented on some platforms for some reason?
For the floating point stuff:
Probably like other per-platform code, this should be done in #ifdefed C.
http://msdn.microsoft.com/en-us/library/e9b52ceh(VS.80).aspx
http://kernel.org/doc/man-pages/online/pages/man3/fetestexcept.3.html
etc.
- Jay
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://m3lists.elegosoft.com/pipermail/m3devel/attachments/20100112/ba0a561e/attachment-0002.html>
More information about the M3devel
mailing list