tiffany352 / rink-rs

Unit conversion tool and library written in rust
https://rinkcalc.app/about
GNU General Public License v3.0
442 stars 28 forks source link

Indicate recurring base-N representations #72

Closed tiffany352 closed 5 months ago

tiffany352 commented 4 years ago

https://en.wikipedia.org/wiki/Repeating_decimal#Extension_to_other_bases

Wikipedia is terrible with math stuff though. I actually found out about these rules from this video, which explains way better:

https://youtu.be/qID2B4MK7Y0?t=673

I think the important rule is this:

If the current remainder is not a multiple of the base, and divides cleanly into base^N - 1 (for base 10, this would be 9, then 99, then 999, and so on), then the remainder represents the N recurring digits.

Base 10 cases

Fraction Divides into Result
1/3 9 / 3 = 3 0.3 recurring
1/7 999 999 / 7 = 142 857 0.142857 recurring
1/9 99 / 9 = 11 0.11 recurring
1/11 99 / 11 = 09 0.09 recurring

Base 2 cases

Fraction Divides into Result
1 / 3 (0b1 / 0b11) 0b11 / 0b11 = 0b01 0b0.01 recurring
1 / 6 (0b1 / 0b110) ? 0b0.001, 01 recurring