negative mfs size at large memory

メッセージ

more than 2^31 bytes are displayed as negative value.
Because ksh can handle integer range of -2^31 ... 2^31-1

On ksh, this is like this;

$ echo $((2147483647))     # 2^31-1
2147483647
$ echo $((2147483647+1))   # 2^31
-2147483648

Here's a concept code to check two strings representing big non-negative integer values.

#!/bin/ksh

function isgreater {
    # check presence of arguments
    #
    [ $# -lt 2 ] && return -- -1

    x=$1
    y=$2

    # Are arguments both form of positive integer?
    #
    case "$x" in
        0|[1-9]*([0-9])) :            ;; # ok, do nothing
                      *) return -- -2 ;; # ng, string is not positive integer 
    esac
    case "$y" in
        0|[1-9]*([0-9])) :            ;; # ok, do nothing
                      *) return -- -2 ;; # ng, string is not positive integer 
    esac

    # Compare it
    #
    if [ ${#x} -gt ${#y} ]; then
        return 0
    elif [ ${#x} -eq ${#y} ]; then
        if [ $x -gt $y ]; then
            return 0
        else
            return 1
        fi
    else
        return 1
    fi
}

isgreater $1 $2
case $? in
    0) echo $1 is greater than $2. ;;
    1) echo $1 is NOT greater than $2. ;;
    *) echo argument format error ;;
esac

Note


recent(50)
2024-10-15 2024-10-14 2024-10-02 2024-09-22 2024-09-20 2024-08-25 2024-08-22 2024-07-31 2024-07-23 2024-05-24 2024-04-22 2024-04-09 2024-02-17 2024-01-31 2023-11-05 2023-10-04 2023-08-28 2023-06-03 2023-05-30 2023-05-01 2023-04-23 2023-04-13 2023-04-12 2023-03-17 2023-02-24 2023-02-23 2023-02-22 2022-12-23 2022-12-13 2022-11-17 2022-11-15 2022-11-14

Front page   Edit Freeze Diff History Attach Copy Rename Reload   New Page list Search Recent changes   Help   RSS of recent changes
Last-modified: 2010-05-21 (Fri) 22:09:04