bigfixed 1.0.0

arbitrary precision fixed-point arithmetic


To use this package, run the following command in your project's root directory:

Manual usage
Put the following dependency into your project's dependences section:

bigfixed

Build Status Coverage Status DUB DUB

This module provides arbitrary precision fixed-point arithmetic.

// Return the square root of `n` to `prec` decimal places by a method of bisection.
string sqrt(ulong n, size_t prec)
{
    import std.conv : to;
    import std.math : ceil, log10;

    immutable size_t q = (prec / log10(2.0)).ceil.to!size_t() + 1;
    auto low = BigFixed(0, q);
    auto high = BigFixed(n, q);

    while ((high - low) != high.resolution) // BigFixed is integer internally.
    {
        immutable BigFixed mid = (high + low) >> 1; // Shift Expressions can be used.
        immutable bool isLess = (mid * mid) < n;
        if (isLess)
        {
            low = mid;
        }
        else
        {
            high = mid;
        }
    }
    return low.toDecimalString(prec);
}
// 10 digits before the 1,000th digit. See http://www.h2.dion.ne.jp/~dra/suu/chi2/heihoukon/2.html
immutable sqrt2_tail = "9518488472";
assert(sqrt(2, 1000)[$ - 10 .. $] == sqrt2_tail);

Documentation

Run dub fetch bigfixed && dub build bigfixed -b docs.

Authors:
  • kotet
Dependencies:
none
Versions:
1.0.1 2017-Aug-13
1.0.0 2017-Aug-09
0.7.1 2017-Jul-24
0.7.0 2017-Jul-20
0.6.0 2017-Jul-03
Show all 16 versions
Download Stats:
  • 0 downloads today

  • 0 downloads this week

  • 0 downloads this month

  • 55 downloads total

Score:
0.7
Short URL:
bigfixed.dub.pm