Skip to content
Snippets Groups Projects
Commit b35eb797 authored by Thomas Kennedy's avatar Thomas Kennedy
Browse files

Add Rust Cleve Moler arbitrary precision example

parent 1f077a48
No related branches found
No related tags found
No related merge requests found
# C++ ignore rules
# General Ignore Rules
**/documentation/
**.o
**.d
# Java ignore rules
**.exe
**.zip
**.class
**.jar
!**wrapper.jar
# Python rules
!**gradle/wrapper/*.jar
**.pyc
**/docs
# Binary Specific Ignore rules
**/ll2
**leak.out*
**storage
**runShapes
**runshapes
**updateRoom
**registration
**pointerReview
# Gradle Ignore rules
**/build
**/.gradle
**/build/
**/.gradle/
# Deploy Rules
**.zip
# Assignment Ignore Rules
**Assignment-0*
# Eclipse Project Rules
**/.project
**/.classpath
# Eclipse Project Ignore Rules
**.project
**.settings
**.classpath
# Latex Ignore Rules
**.aux
# Scratch (temp) File & Directory Ignore rules
Scratch
**.bak
# Latex
**.aux
**.toc
**.dvi
**latexmk
**.fls
**.log
**.out
# Vim rules
**.swp
# Python Coverage (coverage.py) Rules
**/.coverage
**/htmlcov
# Python Disttools
MANIFEST
# Python Tox
**.tox
# Style Check reports
**style-check*
# Rust
**/target
# output comparison
**/out-Rust.txt
**/out-rust.txt
**/out-cpp.txt
# Gcovr rules
**/source/*.html
**.gcda
**.gcno
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "az"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "41a6b78289a33e09b00818ca8c90ab17c5dabb6e74f4b29a6de679c0e0886ade"
[[package]]
name = "fp-error-estimate"
version = "0.1.0"
dependencies = [
"rug",
]
[[package]]
name = "gmp-mpfr-sys"
version = "1.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "63d7f805cf9df081683d463f62864bda8b8e3ce7162a8e11cd0c49f27b8ce89b"
dependencies = [
"libc",
"winapi",
]
[[package]]
name = "libc"
version = "0.2.69"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "99e85c08494b21a9054e7fe1374a732aeadaff3980b6990b94bfd3a70f690005"
[[package]]
name = "rug"
version = "1.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72315b6d9cb7d886fb99724330c47ceb29e923df657c31da3849fe88c0ded710"
dependencies = [
"az",
"gmp-mpfr-sys",
"libc",
]
[[package]]
name = "winapi"
version = "0.3.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8093091eeb260906a183e6ae1abdba2ef5ef2257a21801128899c3fc699229c6"
dependencies = [
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[package]
name = "fp-error-estimate"
version = "0.1.0"
authors = ["Thomas J. Kennedy <tkennedy@cs.odu.edu>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
rug = "1.8.0"
use rug::Float;
fn cleve_moler(desired_precision: u32) -> Float {
let a = Float::with_val(desired_precision, 4.0)
/ Float::with_val(desired_precision, 3.0);
let b = a - Float::with_val(desired_precision, 1.0);
let c = Float::with_val(desired_precision, &b + &b) + &b;
let one = Float::with_val(desired_precision, 1.0);
(c - one).abs()
}
fn main() {
for precision in 1..=1000 {
println!("{:>5} -> {}", precision, cleve_moler(precision));
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment