[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.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
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.