numbers-tool
🔢 Command-line tool to output numbers in various representations
Science Score: 54.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
✓CITATION.cff file
Found CITATION.cff file -
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
○Academic publication links
-
✓Committers with academic emails
1 of 1 committers (100.0%) from academic institutions -
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (8.3%) to scientific vocabulary
Repository
🔢 Command-line tool to output numbers in various representations
Basic Info
Statistics
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
- Releases: 0
Metadata Files
README.md
Numbers Tool
Command-line tool to output numbers in various representations
Copyright © 2019 Teal Dulcet
This program outputs numbers in various representations, including:
- Integer numbers
- Locale format with digit grouping (same as
printf "%'d" <NUMBER>ornumfmt --grouping) - *Arbitrary bases 2 - 36
- Auto-scale to unit (similar to
numfmt --to=<UNIT>, but with more precision) - Roman numerals
- Greek numerals
- *Morse code
- *Braille
- *Text (spelled out)
- *Prime factors (same as
factor) - *Divisors
- *Aliquot sum (sum of all divisors) and if it is perfect, deficient or abundant
- *If it is prime or composite
- Locale format with digit grouping (same as
- Floating point numbers
- Locale format with digit grouping (same as
printf "%'g" <NUMBER>ornumfmt --grouping) - Auto-scale to unit (similar to
numfmt --to=<UNIT>, but with more precision) - Convert fractions and mathematical constants to Unicode characters
- Locale format with digit grouping (same as
* Supports arbitrary-precision/bignums
It is designed as an extension to the existing factor and numfmt commands from GNU Coreutils.
❤️ Please visit tealdulcet.com to support this program and my other software development.
Usage
Requires support for C++17 and 128-bit integers (the __int128/__int128_t type).
Support for arbitrary-precision integers requires the GNU Multiple Precision (GMP) library. On Ubuntu and Debian, run sudo apt-get update and sudo apt-get install libgmp-dev.
Compile without GMP:
* GCC: g++ -std=gnu++17 -Wall -g -O3 -flto numbers.cpp -o numbers
* Clang: clang++ -std=gnu++17 -Wall -g -O3 -flto numbers.cpp -o numbers
Compile with GMP:
* GCC: g++ -std=gnu++17 -Wall -g -O3 -flto numbers.cpp -o numbers -DHAVE_GMP -lgmpxx -lgmp
* Clang: clang++ -std=gnu++17 -Wall -g -O3 -flto numbers.cpp -o numbers -DHAVE_GMP -lgmpxx -lgmp
Run: ./numbers [OPTION(S)]... [NUMBER(S)]...\
If any of the NUMBERS are negative, the first must be preceded by a --. See Help below for full usage information.
If you want this program to be available for all users, install it. Run: sudo mv numbers /usr/local/bin/numbers and sudo chmod +x /usr/local/bin/numbers.
Optional factor command
Optionally configure the program to use an external factor command instead of the builtin prime factorization functionality. This may be faster when factoring some very large numbers, but slower when factoring large ranges of numbers. Just set the FACTOR define near the top of the numbers.cpp file to the factor command path, for example: "/usr/bin/factor". Alternatively, add the -D FACTOR='"<path>"' option when comping the program, for example -D FACTOR='"/usr/bin/factor"'.
On Linux distributions with GNU Coreutils older than 9.0, including Ubuntu and Debian, the factor command (part of GNU Coreutils) is built without arbitrary-precision/bignum support. If this is the case on your system and you are compiling this program with GMP, you would also need to build the factor command with GMP. You can check by running this and checking for any "too large" errors (note that if it was built with arbitrary-precision/bignum support, this may take a few minutes to complete):
bash
factor 9223372036854775807 18446744073709551615 170141183460469231731687303715884105727 340282366920938463463374607431768211455 57896044618658097711785492504343953926634992332820282019728792003956564819967 115792089237316195423570985008687907853269984665640564039457584007913129639935
The above is factor 263 - 1, 264 - 1, 2127 - 1, 2128 - 1, 2255 - 1 and 2256 - 1.
Requires Make and the GNU C compiler.
Build GNU Coreutils
Instructions
```bash # Save current directory DIRNAME=$PWD cd /tmp/ git clone --filter=blob:none https://github.com/coreutils/coreutils.git git clone --filter=blob:none https://github.com/coreutils/gnulib.git GNULIB_SRCDIR="$PWD/gnulib" cd coreutils/ ./bootstrap --gnulib-srcdir="$GNULIB_SRCDIR" ./configure make -j "$(nproc)" CFLAGS="-g -O3 -flto" WERROR_CFLAGS= make -j "$(nproc)" check CFLAGS="-g -O3 -flto" WERROR_CFLAGS= RUN_EXPENSIVE_TESTS=yes RUN_VERY_EXPENSIVE_TESTS=yes # Copy factor command to starting directory cp ./src/factor "$DIRNAME/" ```Build uutils coreutils
uutils coreutils is a cross-platform Rust rewrite of the GNU Coreutils, but does not currently support arbitrary-precision/bignums.
Instructions
Requires Rust: `curl https://sh.rustup.rs -sSf | sh` ```bash # Save current directory DIRNAME=$PWD cd /tmp/ git clone --filter=blob:none https://github.com/uutils/coreutils.git cd coreutils/ make PROFILE=release make -j "$(nproc)" test # Copy factor command to starting directory cp ./target/release/factor "$DIRNAME/" ```Help
``` $ numbers --help Usage: numbers [OPTION(S)]... [NUMBER(S)]... or: numbers
Options:
Mandatory arguments to long options are mandatory for short options too.
-i, --int Integer numbers (default)
-e, --locale Output in Locale format with digit grouping (same as 'printf "%'d"
-f, --float Floating point numbers
-e, --locale Output in Locale format with digit grouping (same as 'printf "%'g" <NUMBER>' or 'numfmt --grouping')
--grouping
--to <UNIT> Auto-scale output numbers to <UNIT> (similar to 'numfmt --to=<UNIT>', but with more precision)
Run 'numfmt --help' for UNIT options.
-c, --fracts Convert fractions and mathematical constants to Unicode characters
Supports all Unicode fractions, Pi and e constants, implies --unicode.
-a, --all Output all of the above (default)
--ascii ASCII (default)
-u, --unicode Unicode
Only affects --roman, --morse and --factors.
-l, --lower Lowercase
Only affects --to-base (with <BASE> > 10), --roman and --greek.
--upper Uppercase (default)
--help Display this help and exit
--version Output version information and exit
Examples: Output everything for -1234 $ numbers -- -1234
Output 0361100 (octal), 123456 and 0x1E240 (hexadecimal) in binary
$ numbers --binary 0361100 123456 0x1E240
Output 11110001001000000 (binary) in base 36
$ numbers --from-base 2 --to-base 36 11110001001000000
Output 123456 in all the bases (Bash syntax)
$ for i in {2..36}; do echo "Base $i: $(numbers --to-base "$i" 123456 | sed -n 's/^.*: //p')"; done
Output 1234 as Unicode Roman numerals
$ numbers --roman --unicode 1234
Convert 1T from ‘SI’ to ‘IEC’ scales
$ numfmt --from=si 1T | numbers --to=iec-i
Output the current time (hour and minute) as text
$ date +%l%n%M | numbers --from-base 10 --text | sed -n 's/^.*: //p'
Output the aliquot sum for 6, 28, 496, 8128, 33550336, 8589869056 and 137438691328
$ numbers --aliquot 6 28 496 8128 33550336 8589869056 137438691328
Output if 3, 7, 31, 127, 8191, 131071 and 524287 are prime or composite
$ numbers --prime 3 7 31 127 8191 131071 524287
Output 1234.25 with Unicode fractions
$ numbers --float --fracts 1234.25
```
Comparison of --to option
This program vs the numfmt command from GNU Coreutils. This program uses up to 7 characters, while numfmt uses up to 5.
Number | This program | numfmt
--- | ---: | ---:
1234 | 1.234K | 1.3K
12345 | 12.35K | 13K
123456 | 123.5K | 124K
999999 | 1000K | 1.0M
1000000 | 1M | 1.0M
1000001 | 1.000M | 1.1M
The examples above use --to=si.
Contributing
Pull requests welcome! Ideas for contributions:
- Add more options
- Output if the number is a Mersenne prime (suggested by Daniel Connelly)
- Add more examples
- Improve the performance
- Use modular inverses, Montgomery reductions and Hensel forms, as the factor command from GNU Coreutils does. See the comments at the top of the
factor.cfile. - Parallelize the prime factorization to improve the performance on large numbers.
- Implement additional algorithms, such as ECM.
- Use modular inverses, Montgomery reductions and Hensel forms, as the factor command from GNU Coreutils does. See the comments at the top of the
- Support outputting Roman numerals greater than 3999 and Greek numerals greater than 9999
- Support arbitrary-precision floating point numbers
- Add tests
- Submit an enhancement request to GNU Coreutils to get this included as an extension to the existing factor and numfmt commands
- Port to other languages (C, Rust, etc.)
Thanks to Daniel Connelly for providing feedback on the usage information!
Owner
- Name: Teal Dulcet
- Login: tdulcet
- Kind: user
- Location: Portland, Oregon
- Website: https://www.tealdulcet.com/
- Repositories: 31
- Profile: https://github.com/tdulcet
👨💻 Computer Scientist, BS, CRTGR, MS @Thunderbird Council member
Citation (CITATION.cff)
cff-version: 1.2.0
title: Numbers Tool
message: >-
If you use this software, please cite it using the
metadata from this file.
type: software
authors:
- given-names: Teal
family-names: Dulcet
orcid: 'https://orcid.org/0000-0001-7950-9915'
repository-code: 'https://github.com/tdulcet/Numbers-Tool'
abstract: >-
A Linux command-line tool to output numbers in various
representations. Designed as an extension to the existing
factor and numfmt commands from GNU Coreutils.
license: GPL-3.0
GitHub Events
Total
- Push event: 3
Last Year
- Push event: 3
Committers
Last synced: 10 months ago
Top Committers
| Name | Commits | |
|---|---|---|
| Teal Dulcet | t****t@p****u | 24 |
Committer Domains (Top 20 + Academic)
Issues and Pull Requests
Last synced: 10 months ago
All Time
- Total issues: 0
- Total pull requests: 0
- Average time to close issues: N/A
- Average time to close pull requests: N/A
- Total issue authors: 0
- Total pull request authors: 0
- Average comments per issue: 0
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 0
- Pull requests: 0
- Average time to close issues: N/A
- Average time to close pull requests: N/A
- Issue authors: 0
- Pull request authors: 0
- Average comments per issue: 0
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
Pull Request Authors
Top Labels
Issue Labels
Pull Request Labels
Dependencies
- actions/checkout v3 composite