AnyDSL/impala

Parsing of float literals with leading decimal point returns wrong numbers

tkemmer opened this issue · 1 comments

I noticed a rather strange behavior of my code when using floating point literals with leading decimal points (like .5 for 0.5). The parser does not complain about the missing number in front of the decimal point, so I assumed that I could just omit any leading zero (like in many other languages). However, the actual number being parsed from .5 is actually 5.0 rather than 0.5. This looks like the decimal point is just used for type checking here but ignored when parsing the number.

Example code:

print_string(".5 == 0.5 ? ");
if .5 == 0.5 {
	print_string("true\n");
} else {
	print_string("false\n");
}

print_string(".5 == 5.0 ? ");
if .5 == 5.0 {
	print_string("true\n");
} else {
	print_string("false\n");
}

Output:

.5 == 0.5 ? false
.5 == 5.0 ? true

Fixed in commit 42f26b9