Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / [DBP] Add very very large numbers

Author
Message
Phaelax
DBPro Master
20
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 10th Nov 2010 11:11 Edited at: 10th Nov 2010 11:11
Attached is a file containing one hundred 50-digit numbers. The program will read the 100 numbers into an array and add them together, displaying the sum and also writing it to a file since it's unlikely to fit the whole number on screen.



It will convert the numbers into strings and work out an answer much like a person would work it out by hand. Because the final sum being calculated is stored as a string, it's internal size in bytes is equal to how many digits it uses. For example, while 42 stored as a number only requires 1 byte of memory, it would require 2 bytes to store as a string.

A double integer (the largest data type available in DB) uses 8 bytes and handles numbers up to 9,223,372,036,854,775,807. Anything larger than that (more than 19 digits) and the language can't natively handle it as a "number". This example uses numbers of 50 digits, more than twice what we could natively support.

Your signature has been erased by a mod please reduce it to 600 x 120.

Attachments

Login to view attachments
Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 16th Nov 2010 12:15
Is this for a project Euler problem?


Do oranges know what colour they are?
Phaelax
DBPro Master
20
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 20th Nov 2010 23:12
hehe, kinda.

"Only the educated are free" ~Epictetus
"Imagination is more important than knowledge..." ~Einstein

Login to post a reply

Server time is: 2024-03-29 13:39:12
Your offset time is: 2024-03-29 13:39:12