num 0.1.10

Simple numerics. This crate contains basic arbitrary-sized integer, rational, and complex types.
docs.rs failed to build num-0.1.10
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Visit the last successful build: num-0.4.0

Simple numerics.

This crate contains arbitrary-sized integer, rational, and complex types.

Example

This example uses the BigRational type and Newton's method to approximate a square root to arbitrary precision:

# #![allow(unstable)]
extern crate num;

use std::num::FromPrimitive;
use num::bigint::BigInt;
use num::rational::{Ratio, BigRational};

fn approx_sqrt(number: u64, iterations: usize) -> BigRational {
    let start: Ratio<BigInt> = Ratio::from_integer(FromPrimitive::from_u64(number).unwrap());
    let mut approx = start.clone();

    for _ in range(0, iterations) {
        approx = (&approx + (&start / &approx)) /
            Ratio::from_integer(FromPrimitive::from_u64(2).unwrap());
    }

    approx
}

fn main() {
    println!("{}", approx_sqrt(10, 4)); // prints 4057691201/1283082416
}