Skip to content

Unexpected results using divMod #22

@axtar

Description

@axtar

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_, &quotient.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() {}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions