lukebhan / numlib

A completely self-dependent aribitrary precision numerical library.
0 stars 1 forks source link

Fix multiplication issue with fft. #1

Open lukebhan opened 4 years ago

lukebhan commented 4 years ago

200*.5 won't return 100. it gets flipped to 0.1

timothycobrien commented 4 years ago

This is much more of a rust-specific question, but let's say I have Bignums a, b, and c, and I want to perform some additions like x = a + b, y = b + c, and z = a + c.

How can I make this actually work? Should I call copy even though it's not yet implemented for bignum, call clone, inline new objects?

lukebhan commented 4 years ago

use clone for now. We need to implement copy for bignum in the future, but you have to make sure to deep copy the vectors in rust. It probably will make us slower.

timothycobrien commented 4 years ago

I think we need to implement versions of things like add or sub that can just borrow the Bignums right @luke-bhan? So that when x = a + b is called it doesn't require a or b to be moved, just their values to be borrowed.

lukebhan commented 4 years ago

I wish.. but I found this a long time ago https://stackoverflow.com/questions/40301864/overloading-the-add-operator-without-copying-the-operands

timothycobrien commented 4 years ago

@luke-bhan https://stackoverflow.com/questions/28005134/how-do-i-implement-the-add-trait-for-a-reference-to-a-struct

Does this not work?

lukebhan commented 4 years ago

brilliant. YES

timothycobrien commented 4 years ago

So I got around multiplying by two (because I can't multiply Bignums in the definition of Bignum multiplication) by adding twice. Any way to make this work for dividing by two? Maybe it's time to convert to binary so I can bit shift lol

lukebhan commented 4 years ago

you should be able to multiply and subtract as you please with bignums. Take a look at the modulo function, I am multiplying an subtracting there.

lukebhan commented 4 years ago

what do you by multiplying bignums in the defintion. If its an operator overload you can, if its the new function I don't think you can.

timothycobrien commented 4 years ago

I'm just working on the alternate implementation of multiplication and so obviously multiplying within that definition is going to lead to some serious looping issues.

Also for now, I think I'm just going to implement a divide by two method and see if this works as a PoC

timothycobrien commented 4 years ago

Ok hard coded in division by two, now need to think about how to solve multiplication of smaller Bignums within my multiplication of Bignums method :)

We should dynamically call a multiplication based on the number of digits in Bignum, for testing purposes we can also call each of them on their own whenever, but I need to use standard carry-based multiplication as a subroutine or else infinite loops galore @luke-bhan

lukebhan commented 4 years ago

thats certainly fine.Obviously the fft division is super buggy. Feel free to just make that a function in the file for now and then you can use just a standard multiplication algo in its place.