WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Number Conversion

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Computing Large Integers

Keywords:     large integers

The new HugeMath extender can do simple arithmetic on numbers up to 2000 digits in length. The following articles discuss workarounds and shortcuts if the HugeMath extender is not used.

Be aware that WinBatch also supports floating point math, which will solve most problems without resorting to the HugeMath extender.


Question:

A simple math problem.

1414*15151*1616*2 returns a result of -1666311872...quite an unexpected result.

I know that large integers of over aprox. 2 billion will produce an unexpected result. Could there be any other problems here.

Is there any way to handle large numbers?

Answer:

On my handy calculator that looks like 69 billion something. Way beyond the province of WinBatch integer math. Floating point math?

Try...

	1414.0 * 15151.0 * 1616.0 * 2.0
You lose precision, but usually that does not count with big numbers

Question #2:

I am trying to use winbatch to get some data throughput readings from network equipment.

My scripts work fine, until the counters start hitting the Gig range... and then they start to do strange things...

I am actully grabbing them from a text string using "parsedata".

According to the Maximum Amounts .txt FAQ on the site here, there is a limitation. Maybe.

It says "Integer constants are built from the digits 0 through 9. They can range in magnitude from negative to positive 2,147,483,648. Constants larger than these permissible magnitudes will produce unpredictable results.

Floating point numbers are limited to 10^300 (10 to the 300th)"

I assume that it actually means Integer numbers, not constants, 'cos mine go crazy!

Anybody got a workaround, or how I could convert them to floats without corrupting the data?

I'm a bit confused...

Answer #2:

Yes, any integer numbers must fall within those ranges. That is the capacity of a 32-bit (long) value. Actually, the limits are (+/-) 2,147,483,647, not 2,147,483,648.

It sounds like you have a counter stored as a text string, and you want to add to it, and then write it back out as a text string. Let's say the counter you read in is 2147483647. You cannot add 1 to it without switching to floating point. The workaround would be to break the large number into two pieces using string functions, use the smaller number as the counter, and then re-assemble the two pieces when you're done. Something like this:

; ----- read the counter here -----
bigcount = "2147483647"
; ---------------------------------

countlen = StrLen(bigcount)
counthold = 0
counter = bigcount
If countlen > 8
    counthold = StrSub(bigcount, 1, countlen - 8)
counter = StrSub(bigcount, countlen - 7, -1)
Endif

; ----- use the counter here -----
counter = counter + 1
; --------------------------------

bigcount = counter
If counthold
    len = StrLen(counter)
    If len > 8
        rolled = StrSub(counter, 1, len - 8)
        counter = StrSub(counter, len - 7, -1)
        counthold = counthold + rolled
    Endif
    bigcount = StrCat(counthold, counter)
Endif

; ----- write the counter here -----
Message("Value", bigcount)
; ----------------------------------


Question:

I am having a problem working with large numbers. I am trying to track a cursor position over a large file and when I attempt to increment the number above 2147483647 I get inaccurate results. I've tried using the INT function with no luck. Any suggestion on how to work around this?

Answer:

Integer constants are built from the digits 0 through 9. They can range in magnitude of approximately two billion. Constants larger than these permissible magnitudes will produce unpredictable results.

In addition, in the current version of WinBatch (at least) there are some optional parameters to some functions that return numbers n a "hugemath" format.

Maybe check out the Hugemath Extender.

Note. If you are using the Hugemath extender, be very careful NOT to do any normal math operations on your numbers, lest you destroy them.


Article ID:   W13031
Filename:   Computing Large Integers.txt
File Created: 2003:01:22:12:43:32
Last Updated: 2003:01:22:12:43:32