#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2010
    Posts
    2
    Rep Power
    0

    (2**31) -1 which is 2147483647 in a awk script variable


    how to store a value greater than (2**31) -1 which is 2147483647 in a awk script variable
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2006
    Posts
    2,636
    Rep Power
    1811
    I've had a look at a couple of man pages, and nothing leaps out - one did suggest that all numbers are held in floating point any way and as that was going to be a suggestion ...!
    How are these numbers being produced, do you need exacting accuracy (i.e., could you divide by 1,000 or 1,024 as appropriate and still get a useful answer)?
    <edit>
    just had a play and awk will handle numbers in excess of 2**31, but to display them properly you need to 'nudge' it into behaving. A plain print will use scientific notation (e.g., 123.45e6) but printf (using %f or %.f as format string) will show pre number (witrh and without decimal points) and %d will cap at 2**31-1.
    </edit>
    Last edited by SimonJM; January 25th, 2010 at 08:01 AM. Reason: Update
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2010
    Posts
    2
    Rep Power
    0
    Thanks Simon!!

    Is it possible for you to explain me with a simple example?
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2006
    Posts
    2,636
    Rep Power
    1811
    This is from memory, so be warned!

    NumFile:
    Code:
    2147483647
    Code:
    awk '{ num=$1*2; printf("%d\n%f\n%.f\n%s\",$1,($1*2),num,(num*2)) }' NumFile
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc

IMN logo majestic logo threadwatch logo seochat tools logo