NEP9 Base literal number syntax - ghewgill/neon-lang GitHub Wiki
This proposes removing the base literal number syntax and adding a new base
module.
Motivation
The base literal number syntax is generally
0#bb#dddd
where bb
is the base (in decimal) and dddd
is the digits of the number in the given base. While compact, this syntax is difficult to read and is only really useful in specialised situations.
base
module
New In order to provide conversions to and from numbers written in different bases, a new base
module is proposed:
%|
| Module: base
|
| Conversions from numbers to and from arbitrary bases.
|%
EXPORT FUNCTION from(base: Number, digits: String): Number
EXPORT FUNCTION to(base: Number, value: Number): String
EXPORT FUNCTION fromBinary(digits: String): Number
EXPORT FUNCTION fromOctal(digits: String): Number
EXPORT FUNCTION fromHex(digits: String): Number
EXPORT FUNCTION toBinary(value: Number): String
EXPORT FUNCTION toOctal(value: Number): String
EXPORT FUNCTION toHex(value: Number): String
The 0#bb#dddd
syntax will be removed. The replacement would be base.from(bb, "dddd")
.