Visit Our UNIX and Linux User Community


KSH arithmatic Integer overflow


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting KSH arithmatic Integer overflow
# 1  
Old 03-09-2004
Question KSH arithmatic Integer overflow

Guys,

I have two big numbers to multiply. In doing do I am getting integer overflow.
I managed to multiply number but this number is useless as KSh does not recognise it as
a valid number. Here is what I am doing

$ expr 999999999999 \* 100
276447132

I got the right value by doing this

$ expr "999999999999 * 100" | bc
99999999999900

But this value can not be used in comparison.

Is it possible to do it in KSH? I am using 32 bit KSH on 64 bit system.
# 2  
Old 03-09-2004
use:
value=$(echo 999999999999 * 100 | bc)
# 3  
Old 04-03-2004
Quote:
Originally posted by Perderabo
use:
value=$(echo 999999999999 * 100 | bc)
Code:
also try it:
awk 'BEGIN{print 999999999999*100}'
1e+14

Smilie

Previous Thread | Next Thread
Test Your Knowledge in Computers #418
Difficulty: Easy
'JavaScript' is a trademark of Oracle Corporation in the United States.
True or False?

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

arithmatic

Hi Guys, I am relatively new to scripting at the moment and am struggling to get the following function to work. For some reason it does not recognise the arithmatic symbol when i select option1. Any help would be greatly appreciated. menu () { echo "==============" echo "Calculator"... (4 Replies)
Discussion started by: somersetdan
4 Replies

2. Shell Programming and Scripting

how to compare string integer with an integer?

hi, how to I do this? i="4.000" if ; then echo "smaller" fi how do I convert the "4.000" to 4? Thanks! (4 Replies)
Discussion started by: h0ujun
4 Replies

3. Shell Programming and Scripting

Integer in conditional ksh statement

Hi, This is confusing me and I would appreciate some help. Consider this script #!/bin/ksh typset -i stat=`ls -l $WORK/stat |wc -l` if (( $stat < 20 )) then echo true else echo false fi If the value of $stat is say 29. When I run this above it echos true and not false.... (7 Replies)
Discussion started by: giles.cardew
7 Replies

4. Shell Programming and Scripting

integer comparison in ksh

Hi, I am just trying to compare integer in ksh. can you please tell me what's wrong with this code... or give me suggestions on alternative. sample code: i=0; if ; then echo inside if fi Thanks in advance! (6 Replies)
Discussion started by: nram_krishna@ya
6 Replies

5. UNIX for Dummies Questions & Answers

Trying a arithmatic on a command line vs scripting.

Hi Everyone! I'm trying to do simple math on a single command line instead of a script which I've already set up using let etc. I can not get the same output to display on a command line. Essentially I would like a=20, b=50, and c=a*b. When I tried: let "A=20, B=50"; let C=A*B; echo $C ... (2 Replies)
Discussion started by: CasperQuiet
2 Replies

6. Shell Programming and Scripting

arithmatic with awk

hi, i am trying some awk arthmatic calculation,i have a problem if any one can help let say if i have a file exm.txt 3 + 2 3 * 2 3 / 2 3 - 2 the output expected is awk -f exm.awk exm.txt 3 + 2 = 5 3 * 2 = 6 3 / 2 = 1.5 3 - 2 = 1 i simply used exm.awk { print $1 " + " $3 "= " $1 +... (3 Replies)
Discussion started by: phone_book
3 Replies

7. Shell Programming and Scripting

"integer" in ksh? how to count with shell

Hy Stupid question, I know. But I can't get the Solution. As I know C / Java / PHP and other languages I can't get the point with ksh :o. in a while/do iteration I like to count up an integer counter. but counter++ doesn't work, also counter=$counter+1 echoes me 0+1+1 when I iterate 2... (3 Replies)
Discussion started by: lucae
3 Replies

8. Programming

warning: integer overflow in expression

I have the following expression: #define GB (1024 * 1024 * 1024) #define TB (1024 * GB) #define MAX_SIZE (3 * TB) off_t current_size; And then the expression... if (current_size > MAX_SIZE) { ... (1 Reply)
Discussion started by: tantric
1 Replies

Featured Tech Videos