Previous in Forum: vba excel user defined   Next in Forum: RAM use
Close
Close
Close
26 comments
Rate Comments: Nested
Guru
United States - Member - New Member Technical Fields - Education - New Member Popular Science - Cosmology - New Member

Join Date: Dec 2006
Location: Boca Raton, Florida
Posts: 576
Good Answers: 13

How to handle 17-digit numbers on my PC?

07/28/2008 4:27 PM

While writing math programs in QBASIC, I noticed that when attempting to display very large integers with more than 8 digits on the monitor, all digits past the 8th place failed to appear. Do I need to use a different programming language, or is this a hardware issue? Can an ordinary PC handle 17-digit numbers?

__________________
Problems worthy of attack prove their worth by hitting back. -- Piet Hein
Register to Reply
Pathfinder Tags: 17-digit number PC
Interested in this topic? By joining CR4 you can "subscribe" to
this discussion and receive notification when new comments are added.

"Almost" Good Answers:

Check out these comments that don't yet have enough votes to be "official" good answers and, if you agree with them, vote them!
Guru
Engineering Fields - Electrical Engineering - New Member

Join Date: Sep 2006
Location: El Lago, Texas, USA
Posts: 2639
Good Answers: 65
#1

Re: How to handle 17-digit numbers on my PC?

07/28/2008 4:35 PM

It's been a long time since I did BASIC, but isn't there a formatting statement that sets the number of digits to display? Or one that specifies long integers?

Register to Reply
Guru
United States - Member - New Member Technical Fields - Education - New Member Popular Science - Cosmology - New Member

Join Date: Dec 2006
Location: Boca Raton, Florida
Posts: 576
Good Answers: 13
#2
In reply to #1

Re: How to handle 17-digit numbers on my PC?

07/28/2008 4:40 PM

bhankiii,

You might be correct, so I'll need to look into your suggestion.

Meanwhile, should a typical PC running Windows XP have any trouble performing calculations with very large numbers? What is the limit?

__________________
Problems worthy of attack prove their worth by hitting back. -- Piet Hein
Register to Reply
Guru
Engineering Fields - Electrical Engineering - New Member

Join Date: Sep 2006
Location: El Lago, Texas, USA
Posts: 2639
Good Answers: 65
#3
In reply to #2

Re: How to handle 17-digit numbers on my PC?

07/28/2008 4:48 PM

I don't know the answer to that, I believe these are 32 bit machines. 232 is 4,294,967,296 -which is fairly large. (It would probably be +/- 2,147,483,648) Larger numbers would be expressed using scientific notation. But the limitation is most likely in your BASIC software.

But I'm a hardware guy.

Register to Reply
Guru

Join Date: Feb 2007
Location: Israel
Posts: 2968
Good Answers: 24
#4
In reply to #3

Re: How to handle 17-digit numbers on my PC?

07/28/2008 6:29 PM

Most 32 bit machines use 24-bit ALU, with the rest of the word for reserved for status-flagging.

Even so, at levels higher than machine code, you can format expressions to any length required. It's simply up to the application's abilities.

I'd look into expression formatting definitions of QBasic for that

Register to Reply
Guru
United States - Member - New Member Technical Fields - Education - New Member Popular Science - Cosmology - New Member

Join Date: Dec 2006
Location: Boca Raton, Florida
Posts: 576
Good Answers: 13
#5
In reply to #4

Re: How to handle 17-digit numbers on my PC?

07/28/2008 6:38 PM

Thank you. I will look more closely at my QBASIC manual. You guys are probably right. After all, if my cheap scientific calculator can easily handle 12 digits, it seems reasonable that my computer should handle more. I need the precision of all 17 digits (17 significant figures) so scientific notation won't help.

I wonder why the term "floating point unit" keep coming to mind (don't remember exactly what it means).

__________________
Problems worthy of attack prove their worth by hitting back. -- Piet Hein
Register to Reply
Guru

Join Date: May 2006
Location: Placerville, CA (38° 45N, 120° 47'W)
Posts: 6215
Good Answers: 248
#9
In reply to #5

Re: How to handle 17-digit numbers on my PC?

07/28/2008 11:38 PM

What kind of input/output data do you have that you really need 17 digits of precision? I doubt it very seriously!

__________________
Teaching is a great experience, but there is no better teacher than experience.
Register to Reply
Guru
United States - Member - New Member Technical Fields - Education - New Member Popular Science - Cosmology - New Member

Join Date: Dec 2006
Location: Boca Raton, Florida
Posts: 576
Good Answers: 13
#18
In reply to #9

Re: How to handle 17-digit numbers on my PC?

07/29/2008 5:51 PM

It's not data, it's an exercise in pure math. I am looking at the properties of certain types of prime numbers.

__________________
Problems worthy of attack prove their worth by hitting back. -- Piet Hein
Register to Reply
Guru
United States - Member - New Member Technical Fields - Education - New Member Popular Science - Cosmology - New Member

Join Date: Dec 2006
Location: Boca Raton, Florida
Posts: 576
Good Answers: 13
#6
In reply to #3

Re: How to handle 17-digit numbers on my PC?

07/28/2008 6:42 PM

I don't know the answer to that, I believe these are 32 bit machines. 232 is 4,294,967,296 -which is fairly large.


I hope that's not an inherent limit, only 10 digits!

__________________
Problems worthy of attack prove their worth by hitting back. -- Piet Hein
Register to Reply
Guru
United Kingdom - Member - Not a New Member Hobbies - Musician - New Member Hobbies - Fishing - New Member

Join Date: May 2006
Location: Reading, Berkshire, UK. Going under cover.
Posts: 9684
Good Answers: 468
#7

Re: How to handle 17-digit numbers on my PC?

07/28/2008 6:45 PM

It all depends on the programming language constraints (unless you do your own thing).

For example, this is from the Visual Basic (VB6) Help:

"Double (double-precision floating-point) variables are stored as IEEE 64-bit (8-byte) floating-point numbers ranging in value from -1.79769313486232E308 to -4.94065645841247E-324 for negative values and from 4.94065645841247E-324 to 1.79769313486232E308 for positive values."

Going further, you can find a number type called DBTYPE_VARNUMERIC (something to do with OLE DB), which supports up to 255 base 10 digits per number (but you can't actually calculate anything without an external chunk of processing software).

If you're prepared to dig in and do some DIY, you can create systems handling numbers to arbitrary precision (how many digits has pi been calculated to?) - but if you emulated an arithmetic processor for very high precision numbers in, eg, QBASIC, you'd have to be prepared to wait a while for the programs to run.

The only constraint the hardware will place on it is processing speed.

__________________
"Love justice, you who rule the world" - Dante Alighieri
Register to Reply Score 1 for Good Answer
Guru
United Kingdom - Member - Not a New Member Hobbies - Musician - New Member Hobbies - Fishing - New Member

Join Date: May 2006
Location: Reading, Berkshire, UK. Going under cover.
Posts: 9684
Good Answers: 468
#16
In reply to #7

Re: How to handle 17-digit numbers on my PC?

07/29/2008 4:18 PM

Further to my assertions above, I messed around with QuickBASIC Extended (the oldest Basic I could find on my current machine), and put a bit of code together which will generate two random numbers, add them & display the result.

It is very inefficient, but (IMHO) shows the idea quite well. I've checked it to 5 digits, and tested it to 10000 digits (just to make sure it runs). It seems to work.

I hope you can see from this example how it could be extended to the other arithmetic operators, and thence to generate pretty well any function you want to arbitrary precision.

Hope it works for you.

10 RANDOMIZE
20 CLS
100 DIM a%(10000)
110 DIM b%(10000)
120 DIM ans%(10001)
130 DIM i%
140 DIM numdigs%
150 DIM cy%
200 REM initialize stuff
210 numdigs% = 10
220 FOR i% = 1 TO numdigs%
230 a%(i%) = INT(10 * RND(1))
240 b%(i%) = INT(10 * RND(1))
250 ans%(i%) = 0
260 NEXT i%
270 cy% = 0
300 REM Do the calculations
310 FOR i% = 1 TO numdigs%
320 ans%(i%) = a%(i%) + b%(i%) + cy%
330 cy% = 0
340 IF ans%(i%) > 9 THEN ans%(i%) = ans%(i%) - 10: cy% = 1
350 NEXT i%
360 ans%(numdigs% + 1) = cy%
400 REM Show results
410 FOR i% = numdigs% TO 1 STEP -1
420 PRINT LTRIM$(STR$(a%(i%)));
430 NEXT i%
440 PRINT : PRINT "+"
450 FOR i% = numdigs% TO 1 STEP -1
460 PRINT LTRIM$(STR$(b%(i%)));
470 NEXT i%
480 PRINT : PRINT "="
490 FOR i% = numdigs% + 1 TO 1 STEP -1
500 PRINT LTRIM$(STR$(ans%(i%)));
510 NEXT i%
520 PRINT
530 INPUT "Press [ENTER] to continue>"; z$
600 STOP

__________________
"Love justice, you who rule the world" - Dante Alighieri
Register to Reply
Guru
United States - Member - New Member Technical Fields - Education - New Member Popular Science - Cosmology - New Member

Join Date: Dec 2006
Location: Boca Raton, Florida
Posts: 576
Good Answers: 13
#20
In reply to #16

Re: How to handle 17-digit numbers on my PC?

07/29/2008 6:09 PM

Thanks to JohnDG and everyone else who replied. I'll chew on what you've told me already, and see where it takes me. The consensus seems to be that the hardware should not prevent me from handling large integers.

By the way, I realize that there are much better programming languages than QBASIC. My older brother is a programmer, and he has repeatedly suggested that I abandon "crappy" QBASIC in favor of something like Python or Squeak. But I am already familiar with BASIC, and since I write programs only for fun, I don't feel sufficiently motivated to learn a new language.

__________________
Problems worthy of attack prove their worth by hitting back. -- Piet Hein
Register to Reply
Guru

Join Date: Oct 2007
Location: Zagreb, Republic of Croatia (native name Hrvatska) ,EU, Europe
Posts: 545
Good Answers: 8
#25
In reply to #20

Re: How to handle 17-digit numbers on my PC?

11/04/2008 3:39 AM

There is good and free Basic at http://gfabasic32.googlepages.com which has LARGE and HUGE type of numbers, and can display result of 18 decimall places.....

__________________
Per Aspera ad Astra
Register to Reply
Guru
United States - Member - New Member Technical Fields - Education - New Member Popular Science - Cosmology - New Member

Join Date: Dec 2006
Location: Boca Raton, Florida
Posts: 576
Good Answers: 13
#26
In reply to #25

Re: How to handle 17-digit numbers on my PC?

11/04/2008 1:49 PM

Thanks Henrik,

I'm still interested in juggling big numbers, so I'll have a look at the site you suggest.

I just wish the day was longer so that I could persue all of my various interests. I would get so much more done, and be able to sleep more hours at night too.

__________________
Problems worthy of attack prove their worth by hitting back. -- Piet Hein
Register to Reply
Anonymous Poster
#8

Re: How to handle 17-digit numbers on my PC?

07/28/2008 9:08 PM

I had a similar problem when moving a program from a IBM 360 (64 bit) to a PDP 11 (15 bit+ sign). The program (cross assembler) needed to count from 0 to 64K. But the PDP could only count from -32k to +32k. First I had to turn off the integer overflow.

Then I designed a way to map the -32k to +32k into 0-64K.

Even though the computer may be able to handle larger integers, you need to check the software that will be doing the calculations to make sure it can also handle it. Most of the old Basic Language was for 8 bit machines, atari,commador,appile II, then the 16 bit machines came out, now the pc is up to 64 bit, but not that much software but it is comming. Try an compiled Basic and not an inturpive version.

Register to Reply
Guru
Engineering Fields - Electrical Engineering - New Member

Join Date: Sep 2006
Location: El Lago, Texas, USA
Posts: 2639
Good Answers: 65
#13
In reply to #8

Re: How to handle 17-digit numbers on my PC?

07/29/2008 10:54 AM

PDP11? My, aren't you an old fart!

Register to Reply
Associate

Join Date: Jul 2008
Posts: 54
Good Answers: 2
#10

Re: How to handle 17-digit numbers on my PC?

07/29/2008 5:36 AM

As long as you are defining them as long (&), you may have to convert it to a string just to display it if i remember correctly. It has been a while since Q Basic for me. The range is only from -2,147,483,647 to +2,147,483,647 though.

a& = 2,147,483,647
Print STR$(a&)

If you need to go higher, you have to write a handling routine that does this for you. I could give some examples if this doesn't help. Let me know.

Register to Reply
Power-User

Join Date: Aug 2007
Posts: 479
Good Answers: 9
#11

Re: How to handle 17-digit numbers on my PC?

07/29/2008 8:55 AM

It depends on the data type.

In C, a short integer type is always two bytes (one byte is 8 bits) and a long is always four bytes.

You should be able to declare a long int in Qbasic as well.

It sounds like you are sending a "short" to the screen when you want "long".

Register to Reply
Guru
United States - Member - New Member Technical Fields - Education - New Member Popular Science - Cosmology - New Member

Join Date: Dec 2006
Location: Boca Raton, Florida
Posts: 576
Good Answers: 13
#19
In reply to #11

Re: How to handle 17-digit numbers on my PC?

07/29/2008 5:53 PM

It sounds like you are sending a "short" to the screen when you want "long".


Thanks, I think you "hit the nail on the head"!

__________________
Problems worthy of attack prove their worth by hitting back. -- Piet Hein
Register to Reply
Guru
United Kingdom - Member - Not a New Member Hobbies - Musician - New Member Hobbies - Fishing - New Member

Join Date: May 2006
Location: Reading, Berkshire, UK. Going under cover.
Posts: 9684
Good Answers: 468
#21
In reply to #19

Re: How to handle 17-digit numbers on my PC?

07/29/2008 6:15 PM

Long integer type in BASIC will still only give you 4 bytes ≡ 32 bits, i.e. -2,147,483,648 to 2,147,483,647.

Another thing you could try (without the DIY approach) is getting yourself VB and using number type Decimal. This will give you 14 bytes worth, i.e. (from the Help):

" +/-79,228,162,514,264,337,593,543,950,335 with no decimal point;
+/-7.9228162514264337593543950335 with 28 places to the right of the decimal; smallest non-zero number is
+/-0.0000000000000000000000000001"

__________________
"Love justice, you who rule the world" - Dante Alighieri
Register to Reply
Guru
United States - Member - New Member Technical Fields - Education - New Member Popular Science - Cosmology - New Member

Join Date: Dec 2006
Location: Boca Raton, Florida
Posts: 576
Good Answers: 13
#22
In reply to #21

Re: How to handle 17-digit numbers on my PC?

07/29/2008 6:34 PM

Maybe I will need to learn Visual Basic. I won't be surprised if QBASIC isn't up to the task. 10 digits is definitely not enough, but 29 digits will do very nicely.

__________________
Problems worthy of attack prove their worth by hitting back. -- Piet Hein
Register to Reply
Guru

Join Date: Dec 2007
Location: Cypress Calif
Posts: 741
Good Answers: 23
#12

Re: How to handle 17-digit numbers on my PC?

07/29/2008 10:49 AM

I don't think the problem is with the processor at all. Some of the early Pentium 4 models had an error in the floating point calculations. If you wanted to test your model dividing 4195835/3145727 should give you the answer 1.33382044913624100. I just did that test using the built-in Windows scientific calculator the results were,..................... 1.33820449136241002477328770106

hopefully I didn't make any typing areas I couldn't cut-and-paste

PS. Of course if you're using a 8088 or earlier machine you probably cannot display that many digits. Just had to get my SA comment in.

__________________
"The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore all progress depends on the unreasonable man" George Shaw
Register to Reply
Guru
United Kingdom - Member - Not a New Member Hobbies - Musician - New Member Hobbies - Fishing - New Member

Join Date: May 2006
Location: Reading, Berkshire, UK. Going under cover.
Posts: 9684
Good Answers: 468
#14
In reply to #12

Re: How to handle 17-digit numbers on my PC?

07/29/2008 11:31 AM

Just did the same sum (4195835/3145727), & got 1.3338204491362410024773287701062 (XP Home scientific calculator). Note the extra "2" on the end!!

(BWT - you should be able to copy'n'paste from/to the calculator using Edit->Copy, Edit->Paste, or Crtl-C & Ctrl-V).

__________________
"Love justice, you who rule the world" - Dante Alighieri
Register to Reply
Guru

Join Date: Dec 2007
Location: Cypress Calif
Posts: 741
Good Answers: 23
#15
In reply to #14

Re: How to handle 17-digit numbers on my PC?

07/29/2008 12:19 PM

Hello John:
I just re-ran the numbers, and I swear there wasn't a 2 there the first time, but it is there now. It must be that error I was talking about, in my typing.

I once calculated the mass of the Sun on a four dollar solar powered calculator (amazing what you can do when you're bored) . When it was all said and done I missed by a few billion tons, but I did have the correct order of magnitude.

I don't know if you heard the joke about the physicist and engineer on the game show, the first one to reach the prize when the curtain opened would win the prize. The rules, run half the distance count to three, then repeat the process until they reach the prize.

The curtain opened to reveal a very scantily clad model, the engineer took off at a dead run, the physicist didn't move. When the host asked the physicist if the lady was appealing to him he replied of course she is, but it's impossible I'll never get there.
When the host caught up with the panting engineer, and informed him that it was impossible to reach the lady, the annoyed engineer replied, I know that, but I can get close enough!

I just rounded off, my solar calculation, or my division should be close enough for engineering. If you don't buy that just remember. To err is human, to really foul things up requires a computer.

BTW thanks for the tip on the cut-and-paste.

__________________
"The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore all progress depends on the unreasonable man" George Shaw
Register to Reply Off Topic (Score 5)
Guru
United Kingdom - Member - Not a New Member Hobbies - Musician - New Member Hobbies - Fishing - New Member

Join Date: May 2006
Location: Reading, Berkshire, UK. Going under cover.
Posts: 9684
Good Answers: 468
#17
In reply to #15

Re: How to handle 17-digit numbers on my PC?

07/29/2008 4:22 PM

ROFCTTSCMWLMAO!!!

(Translation: ROF (Crawling Towards The Scantily Clad Model While) LMAO)

__________________
"Love justice, you who rule the world" - Dante Alighieri
Register to Reply Off Topic (Score 5)
Guru
Popular Science - Cosmology - Let's keep knowledge expanding Engineering Fields - Retired Engineers / Mentors - Hobbies - HAM Radio - New Member

Join Date: Dec 2006
Location: North America, Earth
Posts: 4528
Good Answers: 106
#23

Re: How to handle 17-digit numbers on my PC?

07/30/2008 12:04 AM

You need to define double-precison variables. That will give you 14 or 16 digits. In quick basic is is DEFDBL I think. Qbasic may not have the function.

__________________
“I would rather have questions that can't be answered than answers that can't be questioned.” - Richard Feynman
Register to Reply
Guru

Join Date: Mar 2007
Location: Etherville
Posts: 12362
Good Answers: 115
#24

Re: How to handle 17-digit numbers on my PC?

08/29/2008 1:45 AM

Hi Svengali,

Forgive me for giggling, but I did something similar to what you are attempting. I was messing with multiplying large numbers, and using QBASIC. Like yourself, for amusements sake.

It was a whiles back, but it was essentially setting up a set of n X 1 arrays and mimicking how you would do it longhand. Carry digits were held in an intermediate array. I didn't bother going past about 30 digits, but it would be easy to modify (up to ther arrray limit, which is plenty big enough for playing around)If you get really stuck I'll see if I can dig out the code. It worked a treat, even if a bit ungainly (I never bothered tidying up the modifications as I went along, information comments weren't added etc). There is a free utility called BCalc ( can't recall where from) which is great for tinkering with big numbers, and you can verify your program is OK with it.

I'm assuming you mean large digits in the sense of number of places, not pixels/size of each digit !

__________________
For sale - Signature space. Apply on self addressed postcard..
Register to Reply
Register to Reply 26 comments

"Almost" Good Answers:

Check out these comments that don't yet have enough votes to be "official" good answers and, if you agree with them, vote them!
Copy to Clipboard

Users who posted comments:

Anonymous Poster (1); bhankiii (3); dkwarner (1); Henrik14 (1); JohnDG (5); Kris (1); plancette (1); StandardsGuy (1); svengali (8); user-deleted-9 (1); Yuval (1); YWROADRUNNER (2)

Previous in Forum: vba excel user defined   Next in Forum: RAM use

Advertisement