sellout / bradix

Braille-radix numbers

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bradix

https://img.shields.io/endpoint.svg?url=https%3A%2F%2Fgarnix.io%2Fapi%2Fbadges%2Fsellout%2Fbradix https://repology.org/badge/tiny-repos/bradix.svg https://repology.org/badge/latest-versions/bradix.svg

━━━
bradix
 ━━━━━

Braille-radix numbers

More consistent, less biased numeric notation.

What?

Braille-radix numbers replace the usual radix point (.) with a braille code point that encodes the base of the number in binary.

Here is the value of each dot in a braille code point (the two highest-valued dots lie below the baseline, like descenders on letters):

  1   8
  2  16
  4  32
━━━━━━━
 64 128

And here are some numbers

  • 12 345⠊678 9 (base 10⠊ / decimal)
  • 12 345⠌678 9AB (base 12⠊ / dozenal)
  • 12,345⠐678,9ab (base 16⠊ / hexidecimal)
  • -1 1100⠂0101 0101 (base 2⠊ / binary)

Some things you can see in those examples

  • spaces and commas are valid digit separators
  • digits beyond 9 are represented with case-insensitive English letters (for now)
  • negative numbers are prefixed with - (and positives may be prefixed with +)

Why?

There are various notations numbers in various bases. Sometimes, we don’t need any annotation at all; other times there is a prefix, like 0x or b; and sometimes a decimal number is used to explicitly name the base, as in #12r17 (which is 19 (in decimal) written using base-12) or 17₁₂0 (which is the same, but written using the decimal representation of the base as the radix point.

However, each of these has problems. Leaving off the annotation can be ambiguous sometimes. When you see “17” you can be reasonably sure that the base is at least octal, but nothing tells you definitively what it is. Usually it’ll be decimal, but bare hex numbers aren’t uncommon in some contexts.

The issue with prefixes is that they’re arbitrary and don’t generalize. You just have to know that 0x indicates hexidecimal. Even with prefixes like #12r, it’s contextual that the 12 is decimal. And, why use decimal?

Instead, Bradix uses an ever-present radix point and tries to simplify it as much as possible. I considered a unary system, but it doesn’t have any sort of Unicode support, and it becomes hard to read. Wait … is there 12 dots there or 16? But binary – still representable using only dots, but much more compact. And it has a standard ordering of the dots and Unicode support. So, our bases in binary look like

012345678910111213141516171819202122

And the code points are in the correct ordering for this use case, so you can subtract “BRAILLE PATTERN BLANK” from the code point of your character to figure out the radix.

So 17⠌ is now clearly 19⠊.

bradix-parse extracts a Bradix-formatted number from a string. If you (require 'bradix-reader), then there is also a syntax extension that causes Bradix-formatted numbers prefixed by (the braille numeric indicator) to be read directly as literals.

See bradix-tests.el and bradix-reader-tests.el for some examples.

building

preferred

Especially if you are unfamiliar with the Emacs ecosystem, there is a Nix flake that wraps all the Eldev functionality, and provides overlays, etc.

traditional

This project offers an Eldev build.

comparisons

Emacs

Emacs has a built-in reader-syntax for bases from 2⠊–16⠊. However, it only works for integers.

It uses a prefix like #16r, which is written in base 10⠊. Bradix supports bases 0⠊–255⠊ (but there are currently some bugs related to the higher bases).

About

Braille-radix numbers

License:GNU Affero General Public License v3.0


Languages

Language:Emacs Lisp 57.9%Language:Nix 42.1%