-
Notifications
You must be signed in to change notification settings - Fork 23
Description
I don't know if I'm using divMod correctly because I'm getting unexpected results.
Instead of quotient = 1 and remainder = 2
my code returns:
quotient = 1.00555555555555555555555555555555555555555555555555
remainder = 0.00000000000000000000000000000000000000000000000200
If I change the divMod function like this
void BigNumber::divMod (const BigNumber divisor, BigNumber & quotient, BigNumber & remainder) const
{
bc_divmod (num_, divisor.num_, "ient.num_, &remainder.num_, 0 /*scale_*/);
}
everything works as expected.
bc_divmod seems to add scale_ to the scale of the divisor and then work with that
My code:
#include <Arduino.h>
#include "BigNumber.h"
void setup()
{
Serial.begin(115200);
BigNumber::begin(50);
BigNumber a(362);
BigNumber divisor(360);
BigNumber quotient;
BigNumber remainder;
a.divMod(divisor, quotient, remainder);
Serial.println(quotient);
Serial.println(remainder);
}
void loop() {}