From b35eb79705ea01d4d86722b2cdbe99c876f5cdcb Mon Sep 17 00:00:00 2001 From: "Thomas J. Kennedy" <tkennedy@cs.odu.edu> Date: Sun, 19 Apr 2020 14:53:45 -0400 Subject: [PATCH] Add Rust Cleve Moler arbitrary precision example --- .gitignore | 78 +++++++++++++------ .../FP-ErrorEstimate-Rust/Cargo.lock | 63 +++++++++++++++ .../FP-ErrorEstimate-Rust/Cargo.toml | 10 +++ .../FP-ErrorEstimate-Rust/src/main.rs | 21 +++++ 4 files changed, 150 insertions(+), 22 deletions(-) create mode 100644 FPvsArbitraryPrecision/FP-ErrorEstimate-Rust/Cargo.lock create mode 100644 FPvsArbitraryPrecision/FP-ErrorEstimate-Rust/Cargo.toml create mode 100644 FPvsArbitraryPrecision/FP-ErrorEstimate-Rust/src/main.rs diff --git a/.gitignore b/.gitignore index 3597fdf..c530fdc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,34 +1,68 @@ -# 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 diff --git a/FPvsArbitraryPrecision/FP-ErrorEstimate-Rust/Cargo.lock b/FPvsArbitraryPrecision/FP-ErrorEstimate-Rust/Cargo.lock new file mode 100644 index 0000000..90f429f --- /dev/null +++ b/FPvsArbitraryPrecision/FP-ErrorEstimate-Rust/Cargo.lock @@ -0,0 +1,63 @@ +# 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" diff --git a/FPvsArbitraryPrecision/FP-ErrorEstimate-Rust/Cargo.toml b/FPvsArbitraryPrecision/FP-ErrorEstimate-Rust/Cargo.toml new file mode 100644 index 0000000..e00f5ca --- /dev/null +++ b/FPvsArbitraryPrecision/FP-ErrorEstimate-Rust/Cargo.toml @@ -0,0 +1,10 @@ +[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" diff --git a/FPvsArbitraryPrecision/FP-ErrorEstimate-Rust/src/main.rs b/FPvsArbitraryPrecision/FP-ErrorEstimate-Rust/src/main.rs new file mode 100644 index 0000000..4e5eeac --- /dev/null +++ b/FPvsArbitraryPrecision/FP-ErrorEstimate-Rust/src/main.rs @@ -0,0 +1,21 @@ +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)); + } +} -- GitLab