3

By accident I did

gawk 'BEGIN { print 1.2.3+4; }'

and received

1.24.3

I expected a syntax error because of the two dots in the number.
What happened here ?
Is that a bug in GNU awk or is it a feature ?

Same result with these versions:
GNU Awk 4.1.3, API: 1.1 (GNU MPFR 3.1.4, GNU MP 6.1.0) from Ubuntu 16.04 and
GNU Awk 4.1.0, API: 1.0 (GNU MPFR 3.1.2, GNU MP 4.3.2) from cygwin.

Juergen
  • 578
  • 6
  • 24

1 Answers1

2

The expression

1.2.3+4

gawk parses as two numeric expressions: 1.2 and .3+4.

(The second dot is not allowed to be a part of the first expression, so the parser consider it as the start of another expression.)

The second expression is the sum of .3 and 4, which gawk correctly evaluates, obtaining 4.3.

Then it prints 1.2 and 4.3 (without a delimiter):

1.24.3
MarianD
  • 2,716