Sha256: bfd0a6dc5460c984852b9e9bcb15fabe19861e4a66314c42166a3397c5b0f781
Contents?: true
Size: 692 Bytes
Versions: 10
Compression:
Stored size: 692 Bytes
Contents
/^[ \t]*-?[0-9]+[ \t]+-?[0-9]+[ \t]*$/ { print "add:", $1 + $2 print "sub:", $1 - $2 print "mul:", $1 * $2 print "div:", int($1 / $2) # truncates toward zero print "mod:", $1 % $2 # same sign as first operand print "exp:", $1 ^ $2 exit } For division and modulus, Awk should act like C. '''Exponentiation's note:''' With [[nawk]] or [[gawk]], <code>$1 ** $2</code> acts like <code>$1 ^ $2</code>. With [[mawk]], <code>$1 ** $2</code> is a syntax error. Nawk allows <code>**</code>, but its manual page only has <code>^</code>. Gawk's manual warns, ''"The POSIX standard only specifies the use of `^' for exponentiation. For maximum portability, do not use the `**' operator."''
Version data entries
10 entries across 7 versions & 1 rubygems