https://github.com/evanjbowling/base
Conversion of decimal representations using arbitrary-precision.
https://github.com/evanjbowling/base
clojure clojure-library decimal
Last synced: 8 months ago
JSON representation
Conversion of decimal representations using arbitrary-precision.
- Host: GitHub
- URL: https://github.com/evanjbowling/base
- Owner: evanjbowling
- License: epl-1.0
- Created: 2019-02-13T04:56:11.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2025-04-11T02:22:46.000Z (about 1 year ago)
- Last Synced: 2025-10-11T22:49:26.926Z (9 months ago)
- Topics: clojure, clojure-library, decimal
- Language: Clojure
- Size: 89.8 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# base
[](https://travis-ci.org/evanjbowling/base)
[](https://versions.deps.co/evanjbowling/base)
[](https://clojars.org/com.evanjbowling/base)
A tiny Clojure library for converting decimals to different base representations.
## Quick Start
```bash
clj -Sdeps '{:deps {com.evanjbowling/base {:mvn/version "0.1.0"}}}' \
-e "(require '[com.evanjbowling.base :as b])(b/to-base 1234567.8901M 13)"
```
Output:
```bash
"342C19.B7571B8C9B₁₃"
```
## Install
Leiningen/Boot:
```clojure
[com.evanjbowling/base "0.1.0"]
```
Clojure CLI/deps.edn:
```clojure
com.evanjbowling/base {:mvn/version "0.1.0"}
```
## Use
Review the [Docs](https://evanjbowling.github.io/base/doc/).
```clojure
(require '[com.evanjbowling.base :as b])
```
There are two main functions:
* `to-base` - returns a string representation
* `to-base-seq` - returns a sequence of numeric values (For every value v, 0 <= v < base) with two parts: integer sequence and fractional sequence.
The sequence version is meant to be useful for exploring the whole sequence (the fractional sequence may be infinite) or for encoding the values in another format (e.g. HTML).
### String Representations
The `to-base` function maps every digit value in the sequence to the relevant character for the base.
Convert simple decimals:
```clojure
(b/to-base 16.25M 2) ; "10000.01₂"
(b/to-base 16.25M 16) ; "10.4₁₆"
```
Convert larger decimals:
```clojure
(b/to-base 134983783748.98374983798374M 64) ; "B9tqRVE.-9cHhZXg1G₆₄"
(b/to-base 8561238652.018972M 37) ; "3CH1F0G.0PZaLKFZT7₃₇"
```
Custom digit mapping:
```clojure
(b/to-base 16.25M 2 {:b/digit-mapping "XO"}) ; "OXXXX.XO₂"
```
## TODO
* review convenience fns, add common name aliases
* proper docs
* review rational support
* repeating rationals not currently supported
* document and expand options map with formatting options (add sequence format)
* repeating fractional sequence detection
* branch with spec usage
## Dedicate
This library is dedicated to the second sentence of the second paragraph of sections 5.1 and 5.2 on page 11 of rfc6234.
## License
Copyright © 2019 Evan Bowling
Distributed under the Eclipse Public License version 1.0.