-
Notifications
You must be signed in to change notification settings - Fork 3
NEP9 Base literal number syntax
Greg Hewgill edited this page Nov 18, 2019
·
2 revisions
This proposes removing the base literal number syntax and adding a new base
module.
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.
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")
.