in reply to machine accuracy

you could just throw a use bignum; at the top of your script and not have to deal with numeric limits.

as for that snippet, it seems right to me but I only have a slight clue about math. I believe perl uses double precision numbers on most platforms which means you have 53 bits of precision. I expect somebody will speak up if I'm wrong :)