Xref: utzoo comp.theory:381 comp.misc:8307 comp.lang.misc:4242 Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!brutus.cs.uiuc.edu!jarthur!elroy.jpl.nasa.gov!ames!pacbell!osc!jgk From: jgk@osc.COM (Joe Keane) Newsgroups: comp.theory,comp.misc,comp.lang.misc Subject: Re: Modulus (Re: hashing function for strings) Summary: Implementing math is pretty hard sometimes. Message-ID: <2069@osc.COM> Date: 23 Feb 90 14:36:47 GMT References: <2367@castle.ed.ac.uk> <12077@goofy.megatest.UUCP> Reply-To: jgk@osc.osc.COM (Joe Keane) Followup-To: comp.theory Organization: Object Sciences Corp., Menlo Park, CA Lines: 22 The main problem is that you're trying to assign an operator to one of many possible different functions. I have my favorites, but someone will always want a different one from what you pick. Let's say we just want to convert a floating point number to an integer. There are a number of rounding possibilities, up, down, toward zero, away from zero, and to nearest. And if you're rounding to nearest, what do you do if you're halfway in between? Again you can go up, down, toward zero, away from zero, or my favorite, pick the even one. Just when you think you've got it down, some weird case shows up; for example, should 1 mod -2 be 1 or -1? I won't even get into 0 vs. -0 or infinities and not-a-numbers. Good thing IEEE and ANSI define the way these things should work. Trouble is, they don't always agree with each other. Even in the BASIC on my HP-71 there are four functions to convert a floating point number to an integer, and three functions to take remainders in different ways. I just looked in the Unix manual section RINT(3M) and there are seven functions provided to convert a floating point number to an integer. If you think this is all kid's stuff, try getting the branch cuts right in your complex inverse hyperbolic functions. Fun stuff.