Re: Question about floats and mods...



Jeff <jnoelcook@xxxxxxxxx> wrote in
news:749337.1136567312312.JavaMail.jakarta@xxxxxxxxxxxxxxxxxxxxxx:

> All or any,
>
> How do some computer programs calculate the modulo of a float if
> modulo relates to integers? And can you really call it MOD if you are
> calculating floats, even though, say Excel, calls it Mod?
>
> Any ideas?
>
> Jeff
>

Have you never before run into the same word having different meanings,
in
different contexts?! "Mod" means quite a variety of things. Might be an
equivalence class in number theory context (e.g., not just a single
number). I likely first ran into mod in FORTRAN, as in reducing an
angle to the range [0,2*PI) by something like Y=AMOD(X,TWOPI) - have
not used FORTRAN for ages, and no longer recall the exact syntax. In
EXCEL, it is whatever the language says it is, like in another response.
Note carefully: the parameters are not necessarily integers in every
context! So, you are starting with a bad assumption that MOD (in every
context) applies only to integers.

If you consider that either (or both) of the arguments of mod(a,b) is
negative - be prepared for a significant difference of opinion of
even the sign of the result! An oft-repeated thread, look around in
the sci.math newsgroup archives for quite a bit of "only an idiot
could consider that ..." arguments. [There is no consensus.] The C
language specification (via K&R2 appendix) declines to define a
specific result when either argument is negative.

As for a low-level "How", the Intel chips include a basic FPMOD
instruction that aids in the computation of mod(a,b) when (a,b) are
floating point numbers. The result is exact (presumes that both of
(a,b) are exact).

And, yes, a computer language (and/or program) can call this all mod,
or rem (e.g., remainder) or whatever else suits the fancy of the
language committee and/or programmer. There is nowhere an
enforceable law that "mod applies only to integers".

Enjoy! Patented?!?! Like trying to patent the addition concept! The
implementation dirty-details might be able to be patented or
copyrighted, though. Try exact copying of the Intel chip details, or
the Microsoft C compiler's implementation that uses that chip's
instruction set, and see if bored lawyers come crawling out of where
ever such ilk lurk.

Lynn Killingbeck
.



Relevant Pages

  • Re: Female Intuition and Female Choice
    ... The statement on sharper sense is for instance, ... when the paragraph is read in context. ... but then I'm a man with meager language skills. ... learned skill, which women's gender role pushes them ...
    (talk.origins)
  • Re: Goedel - interesting problem?
    ... >statement of Godel's theorem as you'll get in nontechnical language. ... Probability is integral to inferencing in context, ... Explain the effect of Goedel's theorem to a music major, etc., who has ... If Torkel, read my reply to him just preceding ...
    (sci.logic)
  • Re: Test first as specification
    ... >>> the only valid input string is an infinite string of a's? ... Without some additional knowledge about the language we ... The context you mention below. ... correctness may be a matter of degree. ...
    (comp.object)
  • Re: Official definition of call-by-value (Re: Finding the instance reference...)
    ... important in context. ... OK, but a name is a rather abstract concept, is it not? ... Not at all, it is a fundamental part of Python, analogous to variable. ... The CPython object inthappens to have the *exact* same representation ...
    (comp.lang.python)