[SOLVED] Ensuring large number precision and avoiding float.
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Ensuring large number precision and avoiding float.
Recently in part of my code I've noticed a strange occurance when working with large numbers (greater than the 32-bit range).
What I'd like to know is if anyone knows of a way to ensure that a large integer say "12476476550" for example remains as an int and doesn't get converted to a float.
What's happening is part-way during the code (and strangest of all) when performing a subtraction the number is converting to a float and a small 'decimal' is added despite both numbers in the subtraction being actual whole numbers.
The only thing I can put this down to is a change in the actual data type perl is thinking the variable is and when converting to a float it's loosing precision.
This is an example of the issue:
Input Number: 15892213505
Returns a result like: 3007311616.99999
I've already tried Math::BigInt and use bigint; but both have serious performance impacts which means these aren't able to be used.
Unfortunately my only solution has been to compile another version of perl to run side-by-side with the one built into debian so that I can enable the -Duse64bitint flag. Now I can use the magical 'q' pack flag to get what I need.