Re: Question about floats and mods...
- From: LC Killingbeck <NOTlynn.killingbeck@xxxxxxxxxxxxxxxx>
- Date: Sat, 07 Jan 2006 07:31:29 GMT
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
.
- Follow-Ups:
- Re: Question about floats and mods...
- From: Jeff
- Re: Question about floats and mods...
- References:
- Question about floats and mods...
- From: Jeff
- Question about floats and mods...
- Prev by Date: Re: Question about the prime counting function...
- Next by Date: Re: Unitary rectangular matrix
- Previous by thread: Re: Question about floats and mods...
- Next by thread: Re: Question about floats and mods...
- Index(es):
Relevant Pages
|