Division returning a negative number


 
Thread Tools Search this Thread
Operating Systems HP-UX Division returning a negative number
# 1  
Old 01-20-2011
Data Division returning a negative number

Hi All,

Just faced an interesting thing in HP-UX. I was dividing 2955334616 / 2 by using echo `expr 2955334616 / 2` , and this ofcourse which expects 1477667308 to be returned. But I am getting -669816340 and I am Smilie how exactly this is possible. It is not one of the compliments (Ones or Twos) and not an understandable phenomea.

Can somebody please clarify this interesting phenomena.

Regards,
Andy
# 2  
Old 01-20-2011
32-bit signed "integer" boundary (2147483647). Try echoing the equation into "bc"
# 3  
Old 01-20-2011
Hi Citaylor,

Thanks for the immediate response. But it seems that the same result is being returned.

2955334616
# echo `expr 2955334616 / 2`
-669816340
# echo `expr 2955334616 / 2` | bc
-669816340
# (echo `expr 2955334616 / 2` ) | bc
-669816340
#

Anym more thoughts?

Regards,
Andy Smilie
# 4  
Old 01-20-2011
sorry, I should have been more clear, try:
Code:
echo "2955334616/2" | bc

This User Gave Thanks to citaylor For This Post:
# 5  
Old 01-20-2011
Hi Citaylor,

Thanks very much for the help. Finally I got realization.

Regards,
Andy
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Converting negative number to positive in a file

Hi ALL, I am having semi column separated file as below. I am having negative values for the records starting with 11095. How can I convert that positive number I tried this below seems not working sed 's/ \(*\)$/ -\1/;t;s/\(.*\)-/\1/ myfile myfile... (6 Replies)
Discussion started by: arunkumar_mca
6 Replies

2. Shell Programming and Scripting

Locating the largest number and performing division

I have a tab delimited file with the following format 1 r 109 45 3 5 6 7 2 f 300 249 5 8 10 3 g 120 4 5 110 0 4 t 400 300 250 0 0 ..... ..... 100,000 lines I would like to get the largest number in columns 4, 5, 6, 7, 8 and divide that largest number with the number in column 3.... (4 Replies)
Discussion started by: Kanja
4 Replies

3. Shell Programming and Scripting

Negative number comparison using nawk on Linux

Hi All, I am trying to compare two negative numbers using awk on linux.But it is giving me wrong result.Same code is working perfectly on solaris. print ((0+new_price) < MIN_PRICE) e.g If I try to compare -1.32(new_price) and -500(min_price) using "<" operator, output is 1 i.e true. ... (5 Replies)
Discussion started by: Rashmee
5 Replies

4. Shell Programming and Scripting

Is it possible to Divide a negative number in bash script

I am using a small script to divide some numbers in a given file and display the output in another file. I am getting the following error basename: invalid option -- '5' Try `basename --help' for more information. (standard_in) 1: syntax error The script is : #!/bin/bash for i in `cat... (4 Replies)
Discussion started by: kmnr877
4 Replies

5. Shell Programming and Scripting

Print smallest negative number with corresponding index from a column

considering the following table: ID col1 col2 col3 col4 1 -16.06801249 13.49785832 -56.57087607 -27.00500526 2 -1.53315720 0.71731735 -42.03602078 -39.78554623 3 -1.53315190 0.71731587 -42.03601548 ... (3 Replies)
Discussion started by: Birda
3 Replies

6. Shell Programming and Scripting

Grep for the most negative number

Hello, I am trying to write a bash script which will give me the most negative number. Here is an example input: Ce 3.7729752124 -4.9505731588 -4.1061257680 Ce -6.9156611391 -0.5991784762 7.3051893138 Ce 7.6489739875 0.3513020731 ... (6 Replies)
Discussion started by: sdl27789
6 Replies

7. Shell Programming and Scripting

ignore negative number in script

Hi, does anyone know how to ignore whether a number is negative in a script. E.g. if I have a variable that contains -1200, how do I ignore the minus sign? (1 Reply)
Discussion started by: borderblaster
1 Replies

8. Shell Programming and Scripting

Grep for a negative number

Hi, I want to search for a return code of -3. Using grep "-3" *.* is giving a syntax error. Please suggest as to how can we search for this pattern using grep. Thanks, Krishna (2 Replies)
Discussion started by: kzmatam
2 Replies

9. Programming

C++ how to isdigit() a negative number?

hi people, I have a function which I am passing a stream which is basically postfix notation if(isdigit(in.peek())) { in >> number; nums.push(number); } else if (strchr("+-*/", in.peek( )) != NULL) { in >> symbol; do_operation(symbol, nums, okay); } ... (1 Reply)
Discussion started by: Darklight
1 Replies

10. Shell Programming and Scripting

returning a column number

Hi all, i was doing a small program where if i was to be given the first 3 letters of any month i.e. in the form of Jan or Apr then it would return the column number where it finds a match. To do this i created a 12 element array of months with first 3 letters and if i echo'ed the contents of... (2 Replies)
Discussion started by: scriptingmani
2 Replies
Login or Register to Ask a Question