Skip to content

A safe wrapper of Berkeley SoftFloat based on softfloat-sys. WASM-compatible version

License

Notifications You must be signed in to change notification settings

tacanslabs/softfloat-wrapper

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

66 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

softfloat-wrapper

softfloat-wrapper is a safe wrapper of Berkeley SoftFloat based on softfloat-sys.

Actions Status Crates.io Docs.rs

Requirements

  • Rust 1.64 - core::ffi types in stable
  • rustfmt - used by bindgen to format bindings
  • clang and libclang - used by bindgen to generate some bindings

Usage

[dependencies.softfloat-wrapper]
git = "https://github.com/tacanslabs/softfloat-sys.git"

Example

use softfloat_wrapper::{Float, F16, RoundingMode};

fn main() {
    let a = 0x1234;
    let b = 0x1479;

    let a = F16::from_bits(a);
    let b = F16::from_bits(b);
    let d = a.add(b, RoundingMode::TiesToEven);

    let a = f32::from_bits(a.to_f32(RoundingMode::TiesToEven).to_bits());
    let b = f32::from_bits(b.to_f32(RoundingMode::TiesToEven).to_bits());
    let d = f32::from_bits(d.to_f32(RoundingMode::TiesToEven).to_bits());

    println!("{} + {} = {}", a, b, d);
}

Features

Compared to 0.3.x, architecture specializations are chosen through target triple. Architectures properly supported ATM:

  • Linux x86-64
  • Wasm32

Actual feature gates:

  • native-float - enables conversions from and to native floating-point types
  • f128 - enables quad-precision F128 type

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

About

A safe wrapper of Berkeley SoftFloat based on softfloat-sys. WASM-compatible version

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Rust 100.0%