File Exchange

image thumbnail

Number to Myriad

version 1.3.0.0 (3.57 KB) by Stephen Cobeldick
Convert a number to a string giving the value using Knuth's Myriad/Yllion naming scheme.

0 Downloads

Updated 23 Sep 2017

View License

Convert a numeric scalar into a string giving the number value using Donald Knuth's Myriad (aka -Yllion) number naming scheme, e.g. 1024e6 -> 'Ten Myllion Twenty-Four Hundred Myriad', or '10;2400,0000' as digits.

Syntax:
str = num2myriad(num)
str = num2myriad(num,dgt)

The input numeric value is rounded and the output precision is defined to ensure the least-unexpected output: single=6 digits; double=15 digits; while int/uint values are parsed at their full precision. The function implements an efficient algorithm without using recursion, and with just one for-loop.

### Myriad System (aka -Yllion) ###

Donald Knuth's Myriad number naming system uses a logarithmic increase in group magnitudes for a much more efficient usage of the group names:

10^0 one
10^1 ten
10^2 hundred
10^4 myriad
10^8 myllion
10^16 byllion
10^32 tryllion
10^64 quadryllion
10^128 quintyllion
10^256 sextyllion

Knuth defined the pronunciation as "a myllion (pronounced mile-yun)".

Original Reference: "Supernatural Numbers" by Donald E. Knuth
(pp. 310-325 in The Mathematical Gardner, editor David A. Klarner, 1981)
Online References:
http://en.wikipedia.org/wiki/-yllion
http://mrob.com/pub/math/largenum-2.html
https://sites.google.com/site/pointlesslargenumberstuff/home/1/knuthyllions

### Examples ###

num2myriad(0)
ans = 'Zero'

num2myriad(1024)
ans = 'Ten Hundred Twenty-Four'

num2myriad(intmin('int16'))
ans = 'Negative Three Myriad Twenty-Seven Hundred Sixty-Eight'
num2myriad(intmin('int16'),true)
ans = '-3,2768'

num2myriad(9876543210)
ans = 'Ninety-Eight Myllion Seventy-Six Hundred Fifty-Four Myriad Thirty-Two Hundred Ten'
num2myriad(9876543210,true)
ans = '98;7654,3210'

num2myriad(1e64,false)
ans = 'One Quadryllion'
num2myriad(1e64,true)
ans = '1::0000,0000;0000,0000:0000,0000;0000,0000;;0000,0000;0000,0000:0000,0000;0000,0000'

num2myriad(1e303) % aka one centillion (short scale)
ans = 'Ten Hundred Myriad Myllion Tryllion Sextyllion'

Comments and Ratings (0)

Updates

1.3.0.0

* Correct zip file.

1.3.0.0

* Improve help.

1.3.0.0

* Edit blurb.

1.2.0.0

* Fix bug in myriad parsing (if >1 highest level multiplier).

1.1.0.0

* Replace tabs with four space characters.
* Improve index calculation.

1.0.0.0

* Add image

MATLAB Release Compatibility
Created with R2010b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Discover Live Editor

Create scripts with code, output, and formatted text in a single executable document.


Learn About Live Editor