Skip to main content
added 624 characters in body
Source Link
ilkkachu
  • 147.9k
  • 16
  • 268
  • 441

Presumably your awk works with floating point values, like GNU awk seems to do:

$ gawk 'BEGIN{ a = 11111111111111111111; print a, a/22; }'
11111111111111110656 505050505050505024

It can't store 11111111111111111111 accurately, and it can't store the remainder accurately either (11111111111111111111 / 22 is 505050505050505029.81...).

Your expr seems to have a wider numeric range. Mine doesn't (the one from GNU coreutils 8.26):

$ expr 11111111111111111111 / 22
expr: 11111111111111111111: Numerical result out of range
 

As @steeldriver comments, current versions of GNU awk also have the capability to use the GNU MPFR library for high-precision arithmetic. For example, quad-precision floats are enough to give an accurate answer for this division:

$ gawk -M -v PREC="quad" -v OFMT="%.6f" \
  'BEGIN{ a = 11111111111111111111; print a, a/22; }'
11111111111111111111 505050505050505050.500000

Other that that, bc or Python can be used for arbitrarily large numbers.

Presumably your awk works with floating point values, like GNU awk seems to do:

$ gawk 'BEGIN{ a = 11111111111111111111; print a, a/22; }'
11111111111111110656 505050505050505024

It can't store 11111111111111111111 accurately, and it can't store the remainder accurately either (11111111111111111111 / 22 is 505050505050505029.81...).

Your expr seems to have a wider numeric range. Mine doesn't (the one from GNU coreutils 8.26):

$ expr 11111111111111111111 / 22
expr: 11111111111111111111: Numerical result out of range

bc or Python can be used for arbitrarily large numbers.

Presumably your awk works with floating point values, like GNU awk seems to do:

$ gawk 'BEGIN{ a = 11111111111111111111; print a, a/22; }'
11111111111111110656 505050505050505024

It can't store 11111111111111111111 accurately, and it can't store the remainder accurately either (11111111111111111111 / 22 is 505050505050505029.81...).

Your expr seems to have a wider numeric range. Mine doesn't (the one from GNU coreutils 8.26):

$ expr 11111111111111111111 / 22
expr: 11111111111111111111: Numerical result out of range
 

As @steeldriver comments, current versions of GNU awk also have the capability to use the GNU MPFR library for high-precision arithmetic. For example, quad-precision floats are enough to give an accurate answer for this division:

$ gawk -M -v PREC="quad" -v OFMT="%.6f" \
  'BEGIN{ a = 11111111111111111111; print a, a/22; }'
11111111111111111111 505050505050505050.500000

Other that that, bc or Python can be used for arbitrarily large numbers.

added 12 characters in body
Source Link
ilkkachu
  • 147.9k
  • 16
  • 268
  • 441

Presumably your awk works with floating point values, like GNU awk seems to do:

$ gawk 'BEGIN{ a = 11111111111111111111; print a, a/22; }'
11111111111111110656 505050505050505024

It can't store 11111111111111111111 accurately, and it can't store the remainder accurately either (11111111111111111111 / 22 is 505050505050505029.81...).

Your expr seems to have a wider numeric range. Mine doesn't (the one from GNU coreutils 8.26):

$ expr 11111111111111111111 / 22
expr: 11111111111111111111: Numerical result out of range

bc or Python can be used for arbitrarily large numbers.

Presumably your awk works with floating point values, like GNU awk seems to do:

$ gawk 'BEGIN{ a = 11111111111111111111; print a, a/22; }'
11111111111111110656 505050505050505024

It can't store 11111111111111111111 accurately, and it can't store the remainder accurately either (11111111111111111111 / 22 is 505050505050505029.81...).

Your expr seems to have a wider numeric range. Mine doesn't (the one from GNU coreutils 8.26):

$ expr 11111111111111111111 / 22
expr: 11111111111111111111: Numerical result out of range

bc can be used for arbitrarily large numbers.

Presumably your awk works with floating point values, like GNU awk seems to do:

$ gawk 'BEGIN{ a = 11111111111111111111; print a, a/22; }'
11111111111111110656 505050505050505024

It can't store 11111111111111111111 accurately, and it can't store the remainder accurately either (11111111111111111111 / 22 is 505050505050505029.81...).

Your expr seems to have a wider numeric range. Mine doesn't (the one from GNU coreutils 8.26):

$ expr 11111111111111111111 / 22
expr: 11111111111111111111: Numerical result out of range

bc or Python can be used for arbitrarily large numbers.

Source Link
ilkkachu
  • 147.9k
  • 16
  • 268
  • 441

Presumably your awk works with floating point values, like GNU awk seems to do:

$ gawk 'BEGIN{ a = 11111111111111111111; print a, a/22; }'
11111111111111110656 505050505050505024

It can't store 11111111111111111111 accurately, and it can't store the remainder accurately either (11111111111111111111 / 22 is 505050505050505029.81...).

Your expr seems to have a wider numeric range. Mine doesn't (the one from GNU coreutils 8.26):

$ expr 11111111111111111111 / 22
expr: 11111111111111111111: Numerical result out of range

bc can be used for arbitrarily large numbers.