# dntk
[](https://github.com/nnao45/dntk/actions/workflows/ci.yml)
[](https://github.com/nnao45/dntk/actions/workflows/release.yml)
[](https://github.com/nnao45/dntk/releases/tag/v3.1.0)
[](https://crates.io/crates/dntk)
[](https://hub.docker.com/r/nnao45/dntk/tags?name=v3.1.0)
[](https://raw.githubusercontent.com/nnao45/dntk/master/LICENSE)
[](https://github.com/nnao45/dntk/releases)
dntk is command line's multi-platform ***Interactive*** calculator with bc-compatible syntax and **high-precision arithmetic**.

✔︎ dntk means calculator in a japanese.<br>
✔︎ dntk is bc-compatible calculator with bc-style configurable precision powered by `dashu-decimal` (no external bc required!)<br>
✔︎ dntk syntax is compatible with [GNU bc](https://www.gnu.org/software/bc/). [learn syntax more](https://www.gnu.org/software/bc/manual/html_mono/bc.html)<br>
✔︎ dntk is a NATIVE [The Rust Programming Language](https://rust-lang.org) application.<br>
✔︎ dntk can move cursor, can delete char, can refresh buffer.<br>
✔︎ dntk provides **accurate decimal arithmetic** without floating-point errors.<br>
## ***Current dntk's version:v3.1.0***
Download Page: https://github.com/nnao45/dntk/releases/latest
## ✨ Key Features
### 🎯 High-Precision Arithmetic
- Powered by [`dashu-decimal`](https://crates.io/crates/dashu-decimal) for arbitrary-precision decimals with predictable bc semantics
- Configurable scale (default **20** fractional digits) with faithful truncation just like GNU bc
- **No floating-point errors**: `1 + 0.7 = 1.7` (not 1.69999...)
- Accurate division: `1/3 = .33333333333333333333`
### ⚡ Fast & Lightweight
- **No external dependencies** (bc command not required!)
- Pure Rust implementation for maximum performance
- Optimized expression evaluation with `fasteval` + `dashu-decimal`
### 🌍 True Cross-Platform
- Works out of the box on **Windows, Linux, macOS, and FreeBSD**
- No need to install bc.exe on Windows anymore!
- Single binary, easy deployment
### 🔧 bc-Compatible
- Supports standard bc syntax and functions
- Rich math library: trig/hyperbolic (`sin`, `cos`, `tan`, …), logarithms (`log`, `ln`, `log10`, …), powers (`pow`, `sqrt`, `cbrt`), aggregations (`min`, `max`, `hypot`) plus `length`, `scale`, and Bessel `j(n,x)` — short aliases like `s()`, `c()`, `a()`, `l()`, `e()` still work
- Interactive REPL with cursor movement and editing
### 🏳️🌈 Colorful output
- write color means,
<table>
<tr>
<td>color</td>
<td>means</td>
</tr>
<tr>
<td>cyan</td>
<td>can caluclate & can output</td>
</tr>
<tr>
<td>megenta</td>
<td>can't caluclate, can't output</td>
</tr>
<tr>
<td>yellow</td>
<td>danger input char, output warning</td>
</tr>
<tr>
<td>green</td>
<td>clean buffer message</td>
</tr>
</table>
## Platform
dntk support multi-platform 😊 mac, linux, freebsd, and **windows**!!!
- i686-osx
- x86_64-osx
- i686-linux
- x86_64-linux
- i686-windows
- x86_64-windows
- i686-freebsd
- x86_64-freebsd
## Install
### Mac
```bash
$ brew install nnao45/dntk/dntk
```
### Linux
```bash
$ wget https://github.com/nnao45/dntk/releases/download/v3.1.0/dntk-v3.1.0-x86_64-unknown-linux-musl.zip
$ unzip dntk-v3.1.0-x86_64-unknown-linux-musl.zip
```
### Windows
```bash
$ wget https://github.com/nnao45/dntk/releases/download/v3.1.0/dntk-v3.1.0-x86_64-pc-windows-msvc.zip
$ unzip dntk-v3.1.0-x86_64-pc-windows-msvc.zip
```
### FreeBSD
```bash
$ wget https://github.com/nnao45/dntk/releases/download/v3.1.0/dntk-v3.1.0-x86_64-unknown-freebsd.zip
$ unzip dntk-v3.1.0-x86_64-unknown-freebsd.zip
```
### Cargo
```bash
$ cargo install dntk
```
### zplug
```bash
$ zplug 'nnao45/dntk', as:command, from:gh-r
```
### Docker
Can use dntk docker image,
Look!! Very light weight!!🚀
```bash
$ docker images nnao45/dntk
REPOSITORY TAG IMAGE ID CREATED SIZE
nnao45/dntk latest 3a37b5d989b5 2 hours ago 10.5MB
```
And run,
```bash
$ docker run -it --rm nnao45/dntk:latest
```
### And...
```bash
$ echo 'alias bc=dntk' >> ~/.bashrc
$ echo 'alias bc=dntk' >> ~/.zshrc
```
All OK!! 😎
## Options
```
❯❯❯ dntk -h
Command line's multi-platform interactive calculator with high-precision arithmetic.
USAGE:
dntk [FLAGS] [OPTIONS]
FLAGS:
-h, --help Prints help information
--once Run at only once
-q, --quiet No print information message
--show-limits Print the local limits
-V, --version Prints version information
-w, --white Set White color in a output
OPTIONS:
-i, --inject <inject> Pre-run inject statement to the dntk [default: ]
-s, --scale <scale> Number of decimal places (max 28) [default: 20]
```
**Note**: `--bc-path` option has been removed as dntk no longer requires external bc command!
## Pipe Support
```bash
$ echo "123 * 2" | dntk
246
```
behave, like bc ☺️
## Paste Support
```bash
9.52659947520496999698
```
## Windows Support
**No additional setup required!** 🎉
dntk works out of the box on Windows without installing bc.exe. Just download and run!

### Previous versions (v3.1.0 and earlier)
Older versions required bc.exe installation. If you're using an older version:
```bash
$ choco install gnuwin
```
**Recommendation**: Upgrade to the latest version for better Windows support!
## Keybind
### Basic Key
<table>
<tr>
<td>key</td>
<td>feature</td>
</tr>
<tr>
<td>[, ←</td>
<td>cursor move to left</td>
</tr>
<tr>
<td>], →</td>
<td>cursor move to right</td>
</tr>
<tr>
<td>0~9</td>
<td>Sendkey this number</td>
</tr>
<tr>
<td>Ctrl+C, Enter</td>
<td>Finish dntk app</td>
</tr>
<tr>
<td>Delete, Backspace</td>
<td>Delete current char</td>
</tr>
<tr>
<td>@</td>
<td>Clean buffer</td>
</tr>
</table>
### Basic Operation
<table>
<tr>
<td>key</td>
<td>feature</td>
</tr>
<tr>
<td>+</td>
<td>plus</td>
</tr>
<tr>
<td>-</td>
<td>minus</td>
</tr>
<tr>
<td>*</td>
<td>multiplication</td>
</tr>
<tr>
<td>/</td>
<td>division</td>
</tr>
<tr>
<td>^</td>
<td>exponentiation</td>
</tr>
<tr>
<td>%</td>
<td>remainder</td>
</tr>
</table>
### Operation for Logical
<table>
<tr>
<td>key</td>
<td>feature</td>
</tr>
<tr>
<td>!</td>
<td>boolean, relational</td>
</tr>
<tr>
<td>|</td>
<td>boolean</td>
</tr>
<tr>
<td>&</td>
<td>boolean</td>
</tr>
<tr>
<td>></td>
<td>relational</td>
</tr>
<tr>
<td><</td>
<td>relational</td>
</tr>
<tr>
<td>=</td>
<td>relational</td>
</tr>
</table>
### Using Function
dntk ships the bc classics plus a broad math toolkit:
- **Aliases for bc-style shortcuts**: `s(x) → sin(x)`, `c(x) → cos(x)`, `a(x) → atan(x)`, `l(x) → ln(x)`, `e(x) → exp(x)`
- **Powers & roots**: `sqrt(x)`, `cbrt(x)`, `pow(x,y)`
- **Logs & exponentials**: `ln(x)`, `log10(x)`, `log2(x)`, `log(base,value)` (arbitrary base), `exp(x)`, `expm1(x)`
- **Trigonometric family**: `sin`, `cos`, `tan`, `asin`, `acos`, `atan`, `atan2`
- **Hyperbolic family**: `sinh`, `cosh`, `tanh`, `asinh`, `acosh`, `atanh`
- **Rounding helpers**: `abs`, `sign`, `floor`, `ceil`, `trunc`, `round`
- **Aggregations**: `min(...)`, `max(...)`, `hypot(x,y)`
- **Precision utilities**: `length(x)` (digit count), `scale(x)` (fractional digits), `obase=` for base-2〜36 output
- **Randomness & special**: `rand()` / `rand(n)`, `srand(seed)`, `j(n,x)` Bessel (integer order `n`)
more detail 👉 https://www.gnu.org/software/bc/manual/html_mono/bc.html
## 🔬 Technical Details
### Architecture
dntk uses a hybrid approach for optimal performance and precision:
1. **Expression Parsing**: `fasteval` - Fast and lightweight expression parser
2. **High-Precision Arithmetic**: `rust_decimal` - 28-digit decimal precision
3. **Result Formatting**: bc-compatible output format
### Precision Comparison
| bc | 20 digits (default) | 1.7 | .33333333333333333333 |
| dntk (old) | ~15 digits (f64) | 1.69999... ❌ | .33333333333333331483 ❌ |
| **dntk (new)** | **28 digits** | **1.7 ✅** | **.33333333333333333333 ✅** |
### Dependencies
- `fasteval` - Expression evaluation
- `rust_decimal` - High-precision decimal arithmetic (up to 28 digits)
- Pure Rust implementation (no C library dependencies)
### Why No bc Command Required?
Previous versions wrapped the external `bc` command. The new version:
- Implements bc-compatible arithmetic in pure Rust
- Eliminates subprocess overhead
- Works on all platforms without external dependencies
- Provides better precision (28 vs 20 digits)
# Development Guide
## Compile
### Binary
```bash
$ make
```
### Docker
```bash
$ make docker-build
```
# Contribute
Always Welcome!! 😄
***Have a nice rust hacking days***:sparkles::wink:
## Writer & License
dntk was writed by nnao45 (WORK:Infrastructure Engineer, Twitter:@nnao45, MAIL:n4sekai5y@gmail.com).
This software is released under the MIT License, see LICENSE.