<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Using division operator produces negative values in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/using-division-operator-produces-negative-values/m-p/3313642#M876142</link>
    <description>following code is used in my ksh script and for large non-negative positive integers it is returning "bizarre" negative integer values.  What am I missing here ?&lt;BR /&gt;&lt;BR /&gt;let bytes_K=$bytes/1024&lt;BR /&gt;&lt;BR /&gt;for example,&lt;BR /&gt;bytes_K = 4194304000&lt;BR /&gt;and output of code snippet is:&lt;BR /&gt;-98304&lt;BR /&gt;???&lt;BR /&gt;</description>
    <pubDate>Wed, 23 Jun 2004 17:22:06 GMT</pubDate>
    <dc:creator>Gilbert Standen_1</dc:creator>
    <dc:date>2004-06-23T17:22:06Z</dc:date>
    <item>
      <title>Using division operator produces negative values</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/using-division-operator-produces-negative-values/m-p/3313642#M876142</link>
      <description>following code is used in my ksh script and for large non-negative positive integers it is returning "bizarre" negative integer values.  What am I missing here ?&lt;BR /&gt;&lt;BR /&gt;let bytes_K=$bytes/1024&lt;BR /&gt;&lt;BR /&gt;for example,&lt;BR /&gt;bytes_K = 4194304000&lt;BR /&gt;and output of code snippet is:&lt;BR /&gt;-98304&lt;BR /&gt;???&lt;BR /&gt;</description>
      <pubDate>Wed, 23 Jun 2004 17:22:06 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/using-division-operator-produces-negative-values/m-p/3313642#M876142</guid>
      <dc:creator>Gilbert Standen_1</dc:creator>
      <dc:date>2004-06-23T17:22:06Z</dc:date>
    </item>
    <item>
      <title>Re: Using division operator produces negative values</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/using-division-operator-produces-negative-values/m-p/3313643#M876143</link>
      <description>my first guess would be your running into the limitation for 32 integer numbers&lt;BR /&gt;&lt;BR /&gt;see what you get for numbers less then 2G and then for numbers over 2G&lt;BR /&gt;&lt;BR /&gt;you'll probably have to use something like bc or perl to handle such large numbers</description>
      <pubDate>Wed, 23 Jun 2004 17:25:42 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/using-division-operator-produces-negative-values/m-p/3313643#M876143</guid>
      <dc:creator>curt larson_1</dc:creator>
      <dc:date>2004-06-23T17:25:42Z</dc:date>
    </item>
    <item>
      <title>Re: Using division operator produces negative values</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/using-division-operator-produces-negative-values/m-p/3313644#M876144</link>
      <description>Value field overflowed. Your number is too big for the field. I'm wondering why it never happened to me.&lt;BR /&gt;&lt;BR /&gt;Maybe it did?&lt;BR /&gt;&lt;BR /&gt;:-)&lt;BR /&gt;&lt;BR /&gt;SEP</description>
      <pubDate>Wed, 23 Jun 2004 17:36:50 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/using-division-operator-produces-negative-values/m-p/3313644#M876144</guid>
      <dc:creator>Steven E. Protter</dc:creator>
      <dc:date>2004-06-23T17:36:50Z</dc:date>
    </item>
    <item>
      <title>Re: Using division operator produces negative values</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/using-division-operator-produces-negative-values/m-p/3313645#M876145</link>
      <description>use bc -l&lt;BR /&gt;&lt;BR /&gt;echo "$bytes/1024" | bc -l</description>
      <pubDate>Wed, 23 Jun 2004 17:42:53 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/using-division-operator-produces-negative-values/m-p/3313645#M876145</guid>
      <dc:creator>Sundar_7</dc:creator>
      <dc:date>2004-06-23T17:42:53Z</dc:date>
    </item>
    <item>
      <title>Re: Using division operator produces negative values</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/using-division-operator-produces-negative-values/m-p/3313646#M876146</link>
      <description>The replies are greatly appreciated!&lt;BR /&gt;Got around it by doing my units conversion to Kbytes while within the Oracle engine, but glad to know there was a valid issue there.  I'll have to find a solid piece of code one of these days soon for handling division of large integers!&lt;BR /&gt;Gil</description>
      <pubDate>Wed, 23 Jun 2004 17:43:42 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/using-division-operator-produces-negative-values/m-p/3313646#M876146</guid>
      <dc:creator>Gilbert Standen_1</dc:creator>
      <dc:date>2004-06-23T17:43:42Z</dc:date>
    </item>
    <item>
      <title>Re: Using division operator produces negative values</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/using-division-operator-produces-negative-values/m-p/3313647#M876147</link>
      <description>Run this command to display the range of integers supported:&lt;BR /&gt;&lt;BR /&gt;getconf LONG_MIN&lt;BR /&gt;getconf LONG_MAX&lt;BR /&gt;&lt;BR /&gt;If your vales are outside this range then you need a plan B.&lt;BR /&gt;&lt;BR /&gt;One simple solution is "bc".&lt;BR /&gt;&lt;BR /&gt;Here is an an example:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;&lt;BR /&gt;kbytes()&lt;BR /&gt;{&lt;BR /&gt;  typeset -i10 STAT=0&lt;BR /&gt;  typeset N=${1}&lt;BR /&gt;  shift&lt;BR /&gt;  echo "scale=0; ${N} / 1024" | bc&lt;BR /&gt;  STAT=${?}&lt;BR /&gt;  return ${STAT}&lt;BR /&gt;} # kbytes&lt;BR /&gt;&lt;BR /&gt;BYTES=4194304000&lt;BR /&gt;KBYTES=$(kbytes ${BYTES})&lt;BR /&gt;echo "Result = ${KBYTES} KB"&lt;BR /&gt;&lt;BR /&gt;The "scale=0" set 0 decimal places in the result; "scale=2" would set 2 decimal places"&lt;BR /&gt;&lt;BR /&gt;Man bc for more details. Bc can also be used for floating point calculations -- something that the shell will not do.&lt;BR /&gt;</description>
      <pubDate>Wed, 23 Jun 2004 17:45:12 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/using-division-operator-produces-negative-values/m-p/3313647#M876147</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2004-06-23T17:45:12Z</dc:date>
    </item>
    <item>
      <title>Re: Using division operator produces negative values</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/using-division-operator-produces-negative-values/m-p/3313648#M876148</link>
      <description>Apparently the problem is arising at the "let x=' stmt as well as the arithmetic computation code, e.g.&lt;BR /&gt;&lt;BR /&gt;422 let x=5&lt;BR /&gt;423 echo $x&lt;BR /&gt;5&lt;BR /&gt;424 let x=2000&lt;BR /&gt;425 echo $x&lt;BR /&gt;2000&lt;BR /&gt;426 let x=4194304000&lt;BR /&gt;427 echo $x&lt;BR /&gt;-100663296&lt;BR /&gt;&lt;BR /&gt;now if I do&lt;BR /&gt;&lt;BR /&gt;429 getconf LONG_MIN&lt;BR /&gt;-2147483648&lt;BR /&gt;430 getconf LONG_MAX&lt;BR /&gt;2147483647&lt;BR /&gt;&lt;BR /&gt;Now if I do:&lt;BR /&gt;432 echo "$x/1024" | bc -l&lt;BR /&gt;-98304.00000000000000000000&lt;BR /&gt;&lt;BR /&gt;I'll try out your expanded solution and see if it works for me...it's appreciated!&lt;BR /&gt;</description>
      <pubDate>Wed, 23 Jun 2004 17:58:54 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/using-division-operator-produces-negative-values/m-p/3313648#M876148</guid>
      <dc:creator>Gilbert Standen_1</dc:creator>
      <dc:date>2004-06-23T17:58:54Z</dc:date>
    </item>
    <item>
      <title>Re: Using division operator produces negative values</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/using-division-operator-produces-negative-values/m-p/3313649#M876149</link>
      <description>Mr. Stephenson, your solution is excellent!  I'm sure I shall have cause to use it many times.  It is much appreciated.</description>
      <pubDate>Wed, 23 Jun 2004 18:06:35 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/using-division-operator-produces-negative-values/m-p/3313649#M876149</guid>
      <dc:creator>Gilbert Standen_1</dc:creator>
      <dc:date>2004-06-23T18:06:35Z</dc:date>
    </item>
  </channel>
</rss>

