commanderx16 / x16-rom

Other
153 stars 43 forks source link

VAL() should work for hexadecimal numbers #311

Open mobluse opened 2 years ago

mobluse commented 2 years ago

I think VAL() should work for hexadecimal numbers and not only for decimal as it does now.

PRINT VAL("$FFFFFFF")
should print: 268435455.

I believe it would not be too difficult to implement since the code already exists for converting numbers in code.

PRINT $FFFFFFF
works now, and types: 268435455.

Especially now when HEX$() exists. HEX$() converts without $ as prefix, but I think that's OK since $ could be added easily if one wants. It's also similar to how it works in other BASICs, e.g. GW-BASIC: http://www.antonis.de/qbebooks/gwbasman/hexs.html

In GW-BASIC HEX$() also works for negative numbers, e.g. HEX$(-32768) is "8000", but negative numbers doesn't currently work with X16 BASIC HEX$().

I don't think it's necessary to implement VAL() for binary numbers, even though BIN$() exists, but if one did they should probably have % as prefix, e.g. %101.

FreePascal uses the same prefixes:
https://www.freepascal.org/docs-html/ref/refse6.html

SerOlmy16 commented 2 years ago

I've noticed that both prefixes ($ and %) work when READ-ing from DATA statements, so I think it would make sense for both to also work with VAL().