Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

representing large numbers?

Status
Not open for further replies.

mb111280

Technical User
Oct 24, 2001
9
0
0
GB
i have written a program that deals with large numbers, in this case its the numebr of bytes. It all works fine apart from the 'total' feature. as the program uses very large numbers, (but also small numbers such as 12) when it sums all the values, it rollsover numerous times.

how can i handle this, as as far as im aware you can't specify a large number format.
 
I'm assuming that you're talking about 32-bit integer overflow, rather than floating-point overflow. If that's the case, then Tcl supports 64-bit integer arithmetic (even on 32-bit platforms) as of Tcl 8.4:

"The expr command now supports 64-bit (wide integer) arithmetic. Integer constants unable to fit in a signed 32-bit value are treated as wide integers, unless they exceed the capacity of 64 bits, in which case they are treated as double-precision floating point values. The result of an arithmetic operation is a double if at least one of the operands is a double, a wide integer if at least one of the operands is a wide integer, and a normal integer otherwise.

"The int() function always returns a non-wide integer (converting by dropping the high bits), and the new wide() function always returns a wide integer (converting by sign-extending).

"The incr command can increment variables containing 64-bit values correctly, but can accept only 32-bit values as amounts to increment by."

If you can't move up to Tcl 8.4, or if you're exceeding the capacity of 64-bit integers, then you'll need an extension like mpexpr. Go to the Tcl'ers Wiki ( and check out the page "Mpexpr," for more information.

- Ken Jones, President, ken@avia-training.com
Avia Training and Consulting, 866-TCL-HELP (866-825-4357) US Toll free
415-643-8692 Voice
415-643-8697 Fax
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top