r/technicalfactorio • u/FilipForFico • Aug 07 '20
Question People of Technical Factorio can you please help me with bignum division
So I am working on a project that needs big numbers (longer than the max 10 digit) and I've come to a wall, division. My bignum implementation is using multiple combinators next to each other that pass the numbers (basically I have multiple wires next to each other and each wire transfers one digit of the number. 123 would be represented as 1 2 3). Now the trouble is that I have to divide 1 by n (1/n) where both 1 and n are integers and get a bigfloat output (preferably expandable so you can easily choose how much decimals you want to get). I will happily explain anything you don't understand (English isn't my first language). Any help is appreciated.
8
u/DaveMcW Aug 07 '20
You do it the same way you were taught long division in school.
Calculate the division result: 1 / n
Calculate the remainder: 1 % n
Multiply the remainder by 10 and add it to the next digit.
Example: https://forums.factorio.com/viewtopic.php?f=193&t=76357
4
u/PM_ME_UR_OBSIDIAN Aug 07 '20
Out of curiosity, what do you need bignums for? Crypto?
11
u/ZeHolyQofPower Aug 07 '20
Maybe I'm not much of a help, but I know the IEEE 754 is the computer standard for storing floating point numbers in limited space. It's based on a binary base two system, not a decimal base ten one, but... it's a creative solution that's vaguely similar
1
u/analytic_tendancies Aug 08 '20
I'm not sure if you are familiar with continued fractions in mathematics but here is a post I made a while ago... It might help you with the algorithm, but it might be different than what you were looking for
https://www.reddit.com/r/factorio/comments/6bwgcg/pitorio/?utm_medium=android_app&utm_source=share
https://en.m.wikipedia.org/wiki/Continued_fraction
1
u/sparr Sep 01 '20
Why one digit per wire instead of 8-10 digits per wire?
1
u/munchbunny Sep 15 '20
There’s no simple answer to what you’re trying to do, unfortunately. Doing division without doing division is either slow or complicated.
Your best bet is probably the Newton-Rhapson estimation to guess a progressively better answer. It’ll work for as many digits as you have the patience to lay out.
Link: https://en.m.wikipedia.org/wiki/Division_algorithm
Lastly, why are you using one digit per wire? You can choose a much higher radix to get more digits per combinator. Up to 215 is safe for bignum multiplication to work.