Skip to content

Inverse of big numbers #5

@alatcache

Description

@alatcache

If you try 1/1e{DP+1} using Big.js, where DP is the current value of Big.DP, the result is zero. This inverse function seems to get round the problem ...

function big_inv(number) {
var nu = new Big(String(number));

// Create 1 for inverse
var one = new Big('1');

// A Big for the result
var res = new Big('1');

// Get the number's coefficient
var coef_nu = '0.' + nu.c.join('');
var coef = new Big(coef_nu);

// Invert that
var inv_coef = one.div(coef);

// Change sign of exponent and put into result
res.e = (-1 * nu.e) - 1;
res.c = inv_coef.c;
return res;
}

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