MESSAGE
DATE | 2012-02-25 |
FROM | Ruben Safir
|
SUBJECT | Re: [NYLXS - HANGOUT] Re: c++ question about decimals
|
On Fri, Feb 24, 2012 at 09:33:14AM -0500, Paul Robert Marino wrote: > actually after looking into this further what i really need to do is > grab just the remainder of the result of dividing 2 numbers I think > fmod is the answer im looking for >
What you have to remember is that the conversion from ints to floats is OK but floats to a smaller digit has this long list of possible behaviors and some are underfined.
if you want the remainder, the mod opertator is extremely useful and I use it for psuedorandom generation, but you need to make sure everything is a float of appropriate size.
Ruben
> > On Fri, Feb 24, 2012 at 12:48 AM, Paul Robert Marino > wrote: > > my C programmings a little rusty and i could use some help > > im working on a patch for keepalived i have to modify a portion of the > > code that type casts several variables as a unsigned long however I > > need to change it to an equivalent the will store it with a decimal > > with 2 points of precision, and if possible wont change how other > > parts of the code use the same functions with whole numbers does any > > one have any suggestions. > > > > by the way in case any one is wondering im working on implementing > > centisecond (hundredth) of a second intervals for VRRP per the RFC for > > VRRPv3 http://tools.ietf.org/html/rfc5798 > > so far its going well but there are a few points in the code that are > > doing crazy things like setting a sleep timer to 0 seconds which is > > what I'm trying to fix now. that being said the rest of the patch > > works great i was able to cut my interface failover times in nearly > > down from 8 to less than 3 seconds total.
|
|