commit_hash stringlengths 40 40 | author stringlengths 1 57 | date timestamp[s]date 2010-07-26 04:45:09 2026-04-14 18:21:10 | message stringlengths 8 1.39M | diff stringlengths 68 51.2k | files_changed int64 1 136 | insertions int64 0 2.35k | deletions int64 0 1.9k |
|---|---|---|---|---|---|---|---|
4a831ccca88d9b872720b7f15615103d3e1e5217 | Corey Lowman | 2023-03-28T13:10:33 | Adds rand_distr feature | diff --git a/Cargo.toml b/Cargo.toml
index 4a82c72..dd9194c 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -18,6 +18,7 @@ default = ["std"]
std = ["alloc"]
use-intrinsics = []
alloc = []
+rand_distr = ["dep:rand", "dep:rand_distr"]
[dependencies]
cfg-if = "1.0.0"
diff --git a/src/rand_distr.rs b/src/rand_distr.rs
i... | 2 | 33 | 37 |
6ed9b43b8c68e5766cad53496791c5296f9e71bb | Kathryn Long | 2023-03-28T06:11:06 | import ToString trait with serde, no_std, and alloc. fixes #79 | diff --git a/src/bfloat.rs b/src/bfloat.rs
index 6a68227..7f5041e 100644
--- a/src/bfloat.rs
+++ b/src/bfloat.rs
@@ -1,3 +1,5 @@
+#[cfg(all(feature = "serde", feature = "alloc"))]
+use alloc::string::ToString;
#[cfg(feature = "bytemuck")]
use bytemuck::{Pod, Zeroable};
use core::{
@@ -686,7 +688,7 @@ pub fn serializ... | 2 | 8 | 4 |
ea5b9ac7d389d936aeb394d4bae7e146bad2c3fb | Corey Lowman | 2023-03-22T00:46:44 | #82 Adds Distribution implementations for f16 & bf16 | diff --git a/Cargo.toml b/Cargo.toml
index 5437c3c..937dd75 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -15,6 +15,7 @@ exclude = [".git*", ".editorconfig"]
[features]
default = ["std"]
+sample = ["rand", "rand_distr"]
std = ["alloc"]
use-intrinsics = []
alloc = []
@@ -29,6 +30,8 @@ serde = { version = "1.0", def... | 3 | 133 | 2 |
807f00f6b83419b20942ed240f46ceb36d7de162 | Luke Street | 2023-03-19T16:13:31 | More #[inline] in HalfFloatSliceExt, leading_zeros | diff --git a/src/leading_zeros.rs b/src/leading_zeros.rs
index 6c73148..848afb5 100644
--- a/src/leading_zeros.rs
+++ b/src/leading_zeros.rs
@@ -7,6 +7,7 @@
target_feature = "SPV_INTEL_shader_integer_functions2"
))
))))]
+#[inline]
pub(crate) const fn leading_zeros_u16(x: u16) -> u32 {
x.leading_ze... | 2 | 11 | 0 |
d39a24f603474f4a687523832897ef68425bcf3a | Cameron | 2023-03-05T01:58:19 | derive kani::Arbitrary on f16 and bf16 | diff --git a/src/bfloat.rs b/src/bfloat.rs
index a6c481e..6a68227 100644
--- a/src/bfloat.rs
+++ b/src/bfloat.rs
@@ -35,6 +35,7 @@
#[cfg_attr(feature = "serde", derive(Serialize))]
#[cfg_attr(feature = "bytemuck", derive(Zeroable, Pod))]
#[cfg_attr(feature = "zerocopy", derive(AsBytes, FromBytes))]
+#[cfg_attr(kani,... | 2 | 2 | 0 |
73b9816af3e9deb495f57fcbee2db3157f767f53 | Kathryn Long | 2023-01-24T07:09:00 | add preserves_flags to FCVT asm only | diff --git a/src/binary16/arch/aarch64.rs b/src/binary16/arch/aarch64.rs
index 1308146..9441e76 100644
--- a/src/binary16/arch/aarch64.rs
+++ b/src/binary16/arch/aarch64.rs
@@ -15,7 +15,7 @@ pub(super) unsafe fn f16_to_f32_fp16(i: u16) -> f32 {
"fcvt {0:s}, {1:h}",
out(vreg) result,
in(vreg) ... | 1 | 4 | 4 |
14b78e599914686e308fab1852906e50073fc6dd | Kathryn Long | 2023-01-23T04:51:06 | remove unnecessary unsafe blocks | diff --git a/src/binary16/arch.rs b/src/binary16/arch.rs
index d932b9a..85b5b98 100644
--- a/src/binary16/arch.rs
+++ b/src/binary16/arch.rs
@@ -844,3 +844,5 @@ fn product_f16_fallback<I: Iterator<Item = u16>>(iter: I) -> u16 {
fn sum_f16_fallback<I: Iterator<Item = u16>>(iter: I) -> u16 {
f32_to_f16(iter.map(f16... | 2 | 30 | 52 |
659a1942bf5590abce95bdaded33784eaad02555 | Kathryn Long | 2023-01-23T04:19:33 | add basic arithmetic sanity test for f16 | diff --git a/src/binary16.rs b/src/binary16.rs
index 4266ce7..39a24e0 100644
--- a/src/binary16.rs
+++ b/src/binary16.rs
@@ -1884,6 +1884,17 @@ fn round_to_even_f64() {
);
}
+ #[test]
+ fn arithmetic() {
+ assert_eq!(f16::ONE + f16::ONE, f16::from_f32(2.));
+ assert_eq!(f16::ONE - f1... | 1 | 11 | 0 |
859dedf7fa51e8eb9f50f6f60737705ef4243f26 | Kathryn Long | 2023-01-23T04:12:06 | direct f64 conversions for aarch64 | diff --git a/src/binary16/arch.rs b/src/binary16/arch.rs
index 380634e..d932b9a 100644
--- a/src/binary16/arch.rs
+++ b/src/binary16/arch.rs
@@ -84,7 +84,7 @@ pub(crate) fn f64_to_f16(f: f64) -> u16 {
if x86_feature("f16c") {
unsafe { x86::f32_to_f16_x86_f16c(f as f32) }
} else if aarch64... | 2 | 64 | 18 |
95c9afa2a061521ad4ddaf881243e2fdf9493e1c | Kathryn Long | 2023-01-23T03:25:00 | aarch64 fp16 math operations | diff --git a/Cargo.toml b/Cargo.toml
index e26c032..b445e59 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -20,6 +20,7 @@ use-intrinsics = []
alloc = []
[dependencies]
+cfg-if = "1.0.0"
bytemuck = { version = "1.4.1", default-features = false, features = [
"derive",
], optional = true }
diff --git a/src/binary1... | 6 | 300 | 96 |
d8c9f7a6a9182ea0299caee9561f646d4ba6ed08 | Kathryn Long | 2023-01-23T01:30:01 | remove f16c_target_feature nightly feature which has been stabilized | diff --git a/src/lib.rs b/src/lib.rs
index f821945..810e941 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -177,7 +177,7 @@
feature = "use-intrinsics",
any(target_arch = "x86", target_arch = "x86_64")
),
- feature(stdsimd, f16c_target_feature)
+ feature(stdsimd)
)]
#![doc(html_root_url = "ht... | 1 | 1 | 1 |
390c578fe611ba4e926ad7d5491c2f3da1b9f8f6 | Kathryn Long | 2023-01-23T01:25:36 | add black_box to benchmarks where missing | diff --git a/benches/convert.rs b/benches/convert.rs
index 53bae70..3f00027 100644
--- a/benches/convert.rs
+++ b/benches/convert.rs
@@ -1,4 +1,4 @@
-use criterion::{criterion_group, criterion_main, Bencher, BenchmarkId, Criterion};
+use criterion::{black_box, criterion_group, criterion_main, Bencher, BenchmarkId, Crit... | 1 | 25 | 9 |
59526180645b4b499b018076958cee076985839a | Kathryn Long | 2023-01-09T07:42:21 | use correct arch feature fp16 instead of neon | diff --git a/src/binary16/convert.rs b/src/binary16/convert.rs
index 50cdf54..5280fe1 100644
--- a/src/binary16/convert.rs
+++ b/src/binary16/convert.rs
@@ -13,8 +13,8 @@
macro_rules! convert_fn {
(fn $name:ident($($var:ident : $vartype:ty),+) -> $restype:ty {
- if feature("f16c") { $f16c:expr }
- ... | 2 | 72 | 70 |
f92236894b6584f6ced7f1255d08301057ac2653 | Kathryn Long | 2023-01-09T07:12:03 | swap asm registers | diff --git a/src/binary16/convert/aarch64.rs b/src/binary16/convert/aarch64.rs
index 4baa6dc..948c43d 100644
--- a/src/binary16/convert/aarch64.rs
+++ b/src/binary16/convert/aarch64.rs
@@ -46,8 +46,8 @@ pub(super) unsafe fn f32_to_f16_neon(f: f32) -> u16 {
unsafe {
asm!(
"fcvtl {0:v}.4s, {1:v... | 1 | 2 | 2 |
a78436df4763871f8062039c38f55bb5ef8e25c3 | Kathryn Long | 2023-01-09T07:01:10 | initial aarch64 conversion using asm | diff --git a/src/binary16/convert.rs b/src/binary16/convert.rs
index 8a31854..50cdf54 100644
--- a/src/binary16/convert.rs
+++ b/src/binary16/convert.rs
@@ -8,9 +8,13 @@
))]
mod x86;
+#[cfg(all(feature = "use-intrinsics", target_arch = "aarch64"))]
+mod aarch64;
+
macro_rules! convert_fn {
(fn $name:ident($($... | 2 | 173 | 2 |
2f15f03d6e0928bac2873bfa4d3c7bfc2adceac2 | Kathryn Long | 2023-01-09T04:07:03 | move x86 module to its own file | diff --git a/src/binary16/convert.rs b/src/binary16/convert.rs
index b96910f..8a31854 100644
--- a/src/binary16/convert.rs
+++ b/src/binary16/convert.rs
@@ -2,6 +2,12 @@
use crate::leading_zeros::leading_zeros_u16;
use core::mem;
+#[cfg(all(
+ feature = "use-intrinsics",
+ any(target_arch = "x86", target_arch... | 2 | 135 | 135 |
b8782c2cc02e55b6d6ec450fa5d5734462ccd38e | Kathryn Long | 2023-01-02T02:26:54 | bump criterion dev dependency to 0.4 | diff --git a/Cargo.toml b/Cargo.toml
index ce43ff5..bcdafb4 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -33,7 +33,7 @@ zerocopy = { version = "0.6.0", default-features = false, optional = true }
crunchy = "0.2.2"
[dev-dependencies]
-criterion = "0.3.5"
+criterion = "0.4.0"
quickcheck = "1.0"
quickcheck_macros = "... | 1 | 1 | 1 |
dc91d899cf7503bdd6972f728d7b9184d55a4a0e | Sergey "Shnatsel" Davidoff | 2022-12-31T14:19:51 | Use sized slices in conversion functions | diff --git a/src/binary16/convert.rs b/src/binary16/convert.rs
index b52464f..d694291 100644
--- a/src/binary16/convert.rs
+++ b/src/binary16/convert.rs
@@ -88,7 +88,7 @@ fn f16_to_f64(i: u16) -> f64 {
// detection once at beginning of convert slice method, rather than per chunk
convert_fn! {
- fn f32x4_to_f16x4... | 2 | 20 | 30 |
f24a4e1f23ffc5ea625d170c1231f9e63e4ecc3e | Sergey "Shnatsel" Davidoff | 2022-12-30T12:06:33 | Add #[inline] on fallback functions | diff --git a/src/bfloat/convert.rs b/src/bfloat/convert.rs
index b612a9b..8f258f5 100644
--- a/src/bfloat/convert.rs
+++ b/src/bfloat/convert.rs
@@ -1,6 +1,7 @@
use crate::leading_zeros::leading_zeros_u16;
use core::mem;
+#[inline]
pub(crate) const fn f32_to_bf16(value: f32) -> u16 {
// TODO: Replace mem::tra... | 2 | 8 | 0 |
991346c967f491cdac0fa1de0870d7f4f1c908de | Kathryn Long | 2022-12-14T06:59:02 | fix clippy warning | diff --git a/src/bfloat.rs b/src/bfloat.rs
index d651de6..8b23863 100644
--- a/src/bfloat.rs
+++ b/src/bfloat.rs
@@ -1296,9 +1296,9 @@ fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
where
E: serde::de::Error,
{
- Ok(v.parse().map_err(|_| {
+ v.parse().map_err(|_| {
... | 2 | 4 | 4 |
a4e146440eeb6c7ef78694b70b435c278b3745cf | joseLuís | 2022-07-17T11:42:54 | add total_cmp method | diff --git a/src/bfloat.rs b/src/bfloat.rs
index 56e5756..bf4f2b7 100644
--- a/src/bfloat.rs
+++ b/src/bfloat.rs
@@ -566,6 +566,82 @@ pub fn clamp(self, min: bf16, max: bf16) -> bf16 {
x
}
+ /// Returns the ordering between `self` and `other`.
+ ///
+ /// Unlike the standard partial comparison ... | 2 | 152 | 0 |
d1575092486963b44b01d08c93f7381ba6ea6a07 | charles-r-earp | 2022-07-16T01:18:12 | For target_arch = "spirv", disabled Debug and replaced leading_zeros. | diff --git a/Cargo.toml b/Cargo.toml
index e269cec..09542c1 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -29,11 +29,15 @@ serde = { version = "1.0", default-features = false, features = [
num-traits = { version = "0.2.14", default-features = false, features = ["libm"], optional = true }
zerocopy = { version = "0.6.0",... | 7 | 93 | 15 |
36c1e3f366a24bd0337f700a3d5be73d1dca8d03 | Nilstrieb | 2022-05-31T18:53:31 | Fix exclusive reference obtained from shared reference
`slice.as_ptr` goes through a `&[T]`, which only gives it
permission to read and not write. Fix it by using `as_mut_ptr` instead. | diff --git a/src/slice.rs b/src/slice.rs
index 25944e1..f0dc3e4 100644
--- a/src/slice.rs
+++ b/src/slice.rs
@@ -311,7 +311,7 @@ fn reinterpret_cast(&self) -> &[u16] {
#[inline]
fn reinterpret_cast_mut(&mut self) -> &mut [u16] {
- let pointer = self.as_ptr() as *mut u16;
+ let pointer = self.a... | 1 | 2 | 2 |
723ca074e2443ef2948195c5208c71bfec20b0b2 | Mathieu Poumeyrol | 2022-03-07T15:46:07 | add AsPrimitive impls: from and to self, from and to usize and isize | diff --git a/src/num_traits.rs b/src/num_traits.rs
index e5ee490..4318699 100644
--- a/src/num_traits.rs
+++ b/src/num_traits.rs
@@ -699,6 +699,13 @@ fn as_(self) -> $ty {
};
}
+impl AsPrimitive<f16> for f16 {
+ #[inline]
+ fn as_(self) -> f16 {
+ self
+ }
+}
+
impl_as_primitive_to_f16!(i64, to... | 1 | 22 | 0 |
0389edf4a43304c19eaa23edeb36a2c87da37fde | Alexander Ronald Altman | 2022-03-05T00:57:21 | Add `impl Neg` for references
Since it was missing and all the other numeric traits had reference versions. | diff --git a/src/bfloat.rs b/src/bfloat.rs
index c1c9063..ee3f65e 100644
--- a/src/bfloat.rs
+++ b/src/bfloat.rs
@@ -838,6 +838,15 @@ fn neg(self) -> Self::Output {
}
}
+impl Neg for &bf16 {
+ type Output = <bf16 as Neg>::Output;
+
+ #[inline]
+ fn neg(self) -> Self::Output {
+ Neg::neg(*self)
+... | 2 | 18 | 0 |
005ad4e0ad775befb80e420f1fe753db7747fc40 | Kathryn Long | 2022-01-24T16:52:14 | allow uninit_vec clippy lint for now | diff --git a/src/slice.rs b/src/slice.rs
index 56af0f1..25944e1 100644
--- a/src/slice.rs
+++ b/src/slice.rs
@@ -526,6 +526,7 @@ fn convert_to_f64_slice(&self, dst: &mut [f64]) {
#[cfg(any(feature = "alloc", feature = "std"))]
#[inline]
+ #[allow(clippy::uninit_vec)]
fn to_f32_vec(&self) -> Vec<f32>... | 2 | 6 | 0 |
ce0279c0566fcb8a8be946700e15193263c21a5e | Kathryn Long | 2022-01-24T16:49:07 | allow uninit_vec clippy lint for now | diff --git a/src/slice.rs b/src/slice.rs
index 4289dcc..56af0f1 100644
--- a/src/slice.rs
+++ b/src/slice.rs
@@ -428,6 +428,7 @@ fn convert_to_f64_slice(&self, dst: &mut [f64]) {
#[cfg(any(feature = "alloc", feature = "std"))]
#[inline]
+ #[allow(clippy::uninit_vec)]
fn to_f32_vec(&self) -> Vec<f32>... | 1 | 2 | 0 |
1f21fade4981b90535a4737fbe833b01cf35381b | Kathryn Long | 2021-10-14T00:38:52 | impl ref versions of traits for ease of use | diff --git a/src/bfloat.rs b/src/bfloat.rs
index edcfd06..0e27a94 100644
--- a/src/bfloat.rs
+++ b/src/bfloat.rs
@@ -6,7 +6,7 @@
Binary, Debug, Display, Error, Formatter, LowerExp, LowerHex, Octal, UpperExp, UpperHex,
},
num::{FpCategory, ParseFloatError},
- ops::{Add, Div, Mul, Neg, Rem, Sub},
+ ... | 2 | 420 | 2 |
79f695b83db15fc32a9ba59815c974893521ce8c | Kathryn Long | 2021-09-14T03:21:50 | removed version-sync dev dep to allow dev version | diff --git a/Cargo.toml b/Cargo.toml
index 24fb190..233c206 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,7 +1,7 @@
[package]
name = "half"
# Remember to keep in sync with html_root_url crate attribute
-version = "1.7.1" ... | 2 | 1 | 16 |
8b334997f9f66024d1327064e335d29a970023fe | Kathryn Long | 2021-09-14T02:40:46 | removed docs from deprecated items | diff --git a/src/binary16.rs b/src/binary16.rs
index 4c1301a..f68adc0 100644
--- a/src/binary16.rs
+++ b/src/binary16.rs
@@ -699,119 +699,79 @@ fn as_(self) -> f16 {
note = "all constants moved to associated constants of `f16`"
)]
pub mod consts {
- //! Useful [`f16`] constants
-
use super::f16;
- /... | 3 | 2 | 62 |
1d84e56b681f28e7549314bc770ff662947ce07e | Kathryn Long | 2021-09-14T01:44:37 | deny most doctest warnings | diff --git a/src/lib.rs b/src/lib.rs
index e63988b..e2b892d 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -62,6 +62,7 @@
feature(stdsimd, f16c_target_feature)
)]
#![doc(html_root_url = "https://docs.rs/half/1.7.1")]
+#![doc(test(attr(deny(warnings), allow(unused))))]
#![cfg_attr(docsrs, feature(doc_cfg))]
#[cf... | 1 | 1 | 0 |
3bba2ebe052177a9e992502d3e471db296711112 | Kathryn Long | 2021-09-12T06:23:48 | add doc(cfg) feature annotations for docsrs | diff --git a/src/lib.rs b/src/lib.rs
index 361094b..e63988b 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -62,6 +62,7 @@
feature(stdsimd, f16c_target_feature)
)]
#![doc(html_root_url = "https://docs.rs/half/1.7.1")]
+#![cfg_attr(docsrs, feature(doc_cfg))]
#[cfg(all(feature = "alloc", not(feature = "std")))]
ex... | 2 | 8 | 1 |
0fd4caace4147c0abbe64ad6bc046a705ab6a8d9 | Kathryn Long | 2021-09-12T04:57:32 | fix doc link | diff --git a/src/lib.rs b/src/lib.rs
index 7d59e5a..361094b 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -24,7 +24,7 @@
//! `use-intrinsics` feature to use LLVM intrinsics for hardware conversions. This crate does no
//! checks on whether the hardware supports the feature. This feature currently only works on
//! nig... | 1 | 1 | 1 |
0adb33463e53ba2f75734a4cc9200c503df12a8e | Kathryn Long | 2021-09-11T08:50:24 | fix deprecated calls in bench | diff --git a/Cargo.toml b/Cargo.toml
index 925cb5b..24fb190 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -31,7 +31,7 @@ serde = { version = "1.0", default-features = false, features = [
num-traits = { version = "0.2.14", default-features = false, optional = true }
[dev-dependencies]
-criterion = "0.3"
+criterion = "... | 2 | 146 | 138 |
fbae541fcbd13510120a4b96109bbacfb89df10f | Kathryn Long | 2021-09-11T07:12:31 | fix feature compile error | diff --git a/src/bfloat.rs b/src/bfloat.rs
index 637a8c2..cd318fe 100644
--- a/src/bfloat.rs
+++ b/src/bfloat.rs
@@ -1316,9 +1316,11 @@ fn as_(self) -> bf16 {
mod test {
use super::*;
use core::cmp::Ordering;
+ #[cfg(feature = "num-traits")]
use num_traits::{AsPrimitive, FromPrimitive, ToPrimitive};
... | 2 | 8 | 0 |
ca48f8ddb32b08fd8197b68c9315f9437e9d7840 | Kathryn Long | 2021-09-11T06:50:07 | fix clippy warnings | diff --git a/src/bfloat.rs b/src/bfloat.rs
index ce8ad55..637a8c2 100644
--- a/src/bfloat.rs
+++ b/src/bfloat.rs
@@ -1305,6 +1305,19 @@ fn as_(self) -> bf16 {
impl_as_primitive_bf16_from!(u32, from_f32);
impl_as_primitive_bf16_from!(f32, from_f32);
impl_as_primitive_bf16_from!(f64, from_f64);
+}
+
+#[all... | 5 | 49 | 53 |
50754a861823d22615b75bac2338a752e40f8b6c | Gyunghee Park | 2021-06-07T13:09:39 | Implement Bounded trait | diff --git a/src/bfloat.rs b/src/bfloat.rs
index 8cdd791..ce8ad55 100644
--- a/src/bfloat.rs
+++ b/src/bfloat.rs
@@ -654,7 +654,8 @@ mod impl_num_traits {
use core::ops::{Div, Neg, Rem, Sub};
use num_traits::float::FloatCore;
use num_traits::{
- AsPrimitive, Float, FloatConst, FromPrimitive, Num, ... | 2 | 24 | 2 |
8368404f460fbc14aa9104441196041ed424702f | Mathieu Baudet | 2021-04-25T04:30:58 | mention AsPrimitive in the documentation | diff --git a/src/lib.rs b/src/lib.rs
index 3f24662..6abd0e7 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -30,8 +30,8 @@
//! Support for [`serde`] crate `Serialize` and `Deserialize` traits is provided when the `serde`
//! feature is enabled. This adds a dependency on [`serde`] crate so is an optional cargo feature.
/... | 1 | 2 | 2 |
72f351e754257244926e1124e43957e24a1651cf | Mathieu Baudet | 2021-04-25T03:20:46 | implement AsPrimitive for bf16 and f16 | diff --git a/src/bfloat.rs b/src/bfloat.rs
index 1bd1ff0..8cdd791 100644
--- a/src/bfloat.rs
+++ b/src/bfloat.rs
@@ -653,7 +653,9 @@ mod impl_num_traits {
use core::ops::{Add, Mul};
use core::ops::{Div, Neg, Rem, Sub};
use num_traits::float::FloatCore;
- use num_traits::{Float, FloatConst, FromPrimiti... | 2 | 148 | 2 |
e72536ddf69f3b747ea6b80d82db71b120054cee | Kathryn Long | 2021-01-17T07:59:10 | exclude ci files from packaged crate | diff --git a/Cargo.toml b/Cargo.toml
index fa8b73c..baf202d 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -9,6 +9,7 @@ keywords = ["f16", "bfloat16", "no_std"]
license = "MIT/Apache-2.0"
categories = ["no-std", "data-structures", "encoding"]
edition = "2018"
+exclude = ["/ci", "/*.yml"]
[badges]
appveyor = { repos... | 1 | 1 | 0 |
6a4db99bdd51595bed0e55e19ffa96273007d6ca | Kathryn Long | 2021-01-17T07:23:52 | add hex, octal, and binary string format traits | diff --git a/src/bfloat.rs b/src/bfloat.rs
index 0052915..8d659f7 100644
--- a/src/bfloat.rs
+++ b/src/bfloat.rs
@@ -2,11 +2,13 @@
use serde::{Deserialize, Serialize};
#[cfg(feature = "bytemuck")]
-use bytemuck::{Zeroable, Pod};
+use bytemuck::{Pod, Zeroable};
use core::{
cmp::Ordering,
- fmt::{Debug, Di... | 2 | 182 | 50 |
6c11db97a3c41ed714cb2413de6fb376f4f1ff7f | charles-r-earp | 2020-12-21T20:11:07 | Added FromPrimitive from_f32 / from_f64 | diff --git a/src/bfloat.rs b/src/bfloat.rs
index d2866c9..b00b04b 100644
--- a/src/bfloat.rs
+++ b/src/bfloat.rs
@@ -642,6 +642,8 @@ fn from_i16(n: i16) -> Option<Self> { n.to_f32().map(|x| Self::from_f32(x)) }
fn from_u16(n: u16) -> Option<Self> { n.to_f32().map(|x| Self::from_f32(x)) }
fn from_i32(n... | 2 | 4 | 0 |
efbd3b30d675eec563fca9b2401cfcaad654dea5 | charles-r-earp | 2020-12-21T00:19:09 | Changed Debug to print f32 value | diff --git a/src/bfloat.rs b/src/bfloat.rs
index 8bf231a..1e8c80b 100644
--- a/src/bfloat.rs
+++ b/src/bfloat.rs
@@ -597,7 +597,7 @@ fn from_str(src: &str) -> Result<bf16, ParseFloatError> {
impl Debug for bf16 {
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> {
- write!(f, "0x{:X}", self.0)
+ ... | 2 | 2 | 2 |
aab93b9ff9f7e143c24338c8b9f265b32d03171c | charles-r-earp | 2020-12-20T23:12:45 | Fixed typos. Moved impl to inner module. | diff --git a/src/bfloat.rs b/src/bfloat.rs
index d6c6bfd..d2866c9 100644
--- a/src/bfloat.rs
+++ b/src/bfloat.rs
@@ -1,9 +1,6 @@
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
-#[cfg(feature = "num-traits")]
-use num_traits::{Zero, One, ToPrimitive, FromPrimitive};
-
use core::{
cmp::Ordering,... | 2 | 52 | 70 |
03d8a53edf8d08c6e2c472098469c0287cdbd6cf | charles-r-earp | 2020-12-20T22:45:08 | Added Zero + One + ToPrimitive + FromPrimitive for f16 and bf16 | diff --git a/Cargo.toml b/Cargo.toml
index 5fa235f..6729bc5 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -27,6 +27,11 @@ optional = true
default-features = false
features = ["derive"]
+[dependencies.num-traits]
+version = "0.2.14"
+optional = true
+default-features = false
+
[package.metadata.docs.rs]
features = [... | 3 | 83 | 0 |
997a23cc35ec97f2129269bf8e7115fd4b615337 | charles-r-earp | 2020-12-20T21:34:19 | Optional bytemuck support | diff --git a/Cargo.toml b/Cargo.toml
index 5fa235f..29732c9 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -21,6 +21,12 @@ use-intrinsics = []
serialize = ["serde"] # Deprecated. Use serde directly.
alloc = []
+[dependencies.bytemuck]
+version = "1.4.1"
+optional = true
+default-features = false
+features = ["derive"]... | 3 | 14 | 0 |
cb986c589d66c7eecbf31a372430a7221f2f054c | Kathryn Long | 2020-05-10T03:13:29 | fix Rust 1.32 CI failures | diff --git a/Cargo.toml b/Cargo.toml
index 08e8812..b642615 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -33,9 +33,9 @@ features = ["std", "serde"]
[dev-dependencies]
criterion = "0.3"
quickcheck = "0.9"
-quickcheck_macros = "0.8"
+quickcheck_macros = "0.9"
rand = "0.7"
-version-sync = "0.9"
+version-sync = "0.8"
... | 1 | 2 | 2 |
cefe16a64325658a7f9b1b134576cb6c0eacaf52 | Kathryn Long | 2020-05-10T03:12:09 | fix for 1.32 CI | diff --git a/Cargo.toml b/Cargo.toml
index 318af71..08e8812 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -33,7 +33,7 @@ features = ["std", "serde"]
[dev-dependencies]
criterion = "0.3"
quickcheck = "0.9"
-quickcheck_macros = "0.9"
+quickcheck_macros = "0.8"
rand = "0.7"
version-sync = "0.9" | 1 | 1 | 1 |
0e4bf88dc066ae636b71331b677133f87f3b87e9 | Kathryn Long | 2020-05-10T02:21:04 | add from_*_bytes methods | diff --git a/src/bfloat.rs b/src/bfloat.rs
index f470e76..09ad035 100644
--- a/src/bfloat.rs
+++ b/src/bfloat.rs
@@ -116,6 +116,55 @@ pub const fn to_bits(self) -> u16 {
self.0.to_ne_bytes()
}
+ /// Create a floating point value from its representation as a byte array in little endian.
+ ///
+ ... | 2 | 98 | 0 |
4626ff4f2f3da4ca9a67bc703b6bf6faa07f3f43 | Kathryn Long | 2020-05-10T02:10:28 | add doctests and copy to_*_bytes methods to bfloat | diff --git a/src/bfloat.rs b/src/bfloat.rs
index 44ec180..f470e76 100644
--- a/src/bfloat.rs
+++ b/src/bfloat.rs
@@ -64,6 +64,58 @@ pub const fn to_bits(self) -> u16 {
self.0
}
+ /// Return the memory representation of the underlying bit representation as a byte array in
+ /// little-endian byte o... | 2 | 83 | 0 |
7a5c9be6adfe903568a5b3ed0646bed18d22a322 | Kathryn Long | 2020-05-10T01:47:49 | remove `to_le` and `to_be`, see comments in PR #34 | diff --git a/src/binary16.rs b/src/binary16.rs
index 643317f..4b23498 100644
--- a/src/binary16.rs
+++ b/src/binary16.rs
@@ -291,22 +291,6 @@ pub const fn to_bits(self) -> u16 {
self.0
}
- /// Converts `self` to little endian from the target's endianness.
- ///
- /// On little endian this is a ... | 1 | 0 | 16 |
989f9418ac1fc1468166920df08ffc8610f37064 | Kathryn Long | 2020-05-10T01:33:54 | bump version-sync dev dependency | diff --git a/Cargo.toml b/Cargo.toml
index b642615..318af71 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -35,7 +35,7 @@ criterion = "0.3"
quickcheck = "0.9"
quickcheck_macros = "0.9"
rand = "0.7"
-version-sync = "0.8"
+version-sync = "0.9"
[[bench]]
name = "convert" | 1 | 1 | 1 |
00832815237134445be71cbc9858e4243dea5ce4 | Brian Merchant | 2020-04-19T19:46:59 | add methods to_le/be and to_le/be/ne_bytes for f16 | diff --git a/src/binary16.rs b/src/binary16.rs
index e440e5d..14008d3 100644
--- a/src/binary16.rs
+++ b/src/binary16.rs
@@ -291,6 +291,43 @@ pub const fn to_bits(self) -> u16 {
self.0
}
+ /// Converts `self` to little endian from the target's endianness.
+ ///
+ /// On little endian this is a ... | 1 | 37 | 0 |
9c7df992617a1d44d79243810645880d26ff8b73 | Trevor Spiteri | 2020-04-08T11:56:19 | add LOG10_2 and LOG2_10 constants | diff --git a/src/bfloat.rs b/src/bfloat.rs
index d0603c4..44ec180 100644
--- a/src/bfloat.rs
+++ b/src/bfloat.rs
@@ -344,8 +344,12 @@ pub const fn is_sign_negative(self) -> bool {
pub const LN_2: bf16 = bf16(0x3F31u16);
/// [`bf16`](struct.bf16.html) 𝗅𝗈𝗀₁₀ℯ
pub const LOG10_E: bf16 = bf16(0x3EDEu16);
+... | 2 | 32 | 0 |
79a4a4df9740eec8c26066f2d4bbaef5adb95544 | Kathryn Long | 2020-03-03T06:10:01 | add alloc feature | diff --git a/Cargo.toml b/Cargo.toml
index 56b81e1..de3ccdd 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -16,9 +16,10 @@ travis-ci = { repository = "starkat99/half-rs" }
maintenance = { status = "passively-maintained" }
[features]
-std = []
+std = ["alloc"]
use-intrinsics = []
serialize = ["serde"] # Deprecated. U... | 1 | 3 | 2 |
d0699875a455387016238f5255f0f226c04d0b88 | U-FORTIS\14177158 | 2020-03-02T10:20:21 | +alloc feature | diff --git a/src/lib.rs b/src/lib.rs
index a5fddf7..345801f 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -57,6 +57,7 @@
)]
#![allow(clippy::verbose_bit_mask, clippy::cast_lossless)]
#![cfg_attr(not(feature = "std"), no_std)]
+
#![cfg_attr(
all(
feature = "use-intrinsics",
@@ -66,10 +67,13 @@
)]
#![do... | 2 | 9 | 2 |
1fcb79248960750990021785616d80527411c65a | Jody Sankey | 2020-02-28T00:14:33 | Fix as_ptr() -> as_mut_ptr() finding from Miri.
I'm adding a dependency on half to a large project and wanted to give it a quick
check with miri. The miri stacked borrows checker had an issue with using a non
mutable pointer in the mutable reinterpret cast. Its not clear to me if this
was really indicative of a proble... | diff --git a/src/slice.rs b/src/slice.rs
index ef796a7..954aabe 100644
--- a/src/slice.rs
+++ b/src/slice.rs
@@ -568,7 +568,7 @@ fn reinterpret_cast_mut<H>(&mut self) -> &mut [H]
where
H: crate::private::SealedHalf,
{
- let pointer = self.as_ptr() as *mut H;
+ let pointer = self.as_mut_... | 1 | 1 | 1 |
a6e369c5bd439d464acc46dc5fbc8f570e436eec | Julian Frimmel | 2020-02-09T10:41:24 | Add `#[repr(transparent)]` to `f16`/`bf16` types
Currently this crate wraps an `u16` using a tuple struct into a new
type. This is fine, as long the memory representation of this new type
is irrelevant (as it is in safe Rust code).
Unfortunately, there is at least one function, that reinterprets an
`u16` into a `f16` ... | diff --git a/src/bfloat.rs b/src/bfloat.rs
index ed0b0bd..d0603c4 100644
--- a/src/bfloat.rs
+++ b/src/bfloat.rs
@@ -26,6 +26,7 @@
/// [`f16`]: struct.f16.html
#[allow(non_camel_case_types)]
#[derive(Clone, Copy, Default)]
+#[repr(transparent)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub str... | 2 | 2 | 0 |
37be16a45134680cb26ac4efdb479094064435c8 | Kathryn Long | 2019-10-13T03:33:00 | add should_panic tests | diff --git a/src/binary16/convert.rs b/src/binary16/convert.rs
index c7fa094..c2521d8 100644
--- a/src/binary16/convert.rs
+++ b/src/binary16/convert.rs
@@ -82,6 +82,9 @@ fn f16_to_f64(i: u16) -> f64 {
}
}
+// TODO: While SIMD versions are faster, further improvements can be made by doing runtime feature
+// de... | 2 | 35 | 0 |
fbaef028d51f31c80414e71a3a75f69cb14a087f | Kathryn Long | 2019-10-13T03:19:41 | fix benchmarks | diff --git a/benches/convert.rs b/benches/convert.rs
index 9f28a10..4801c8d 100644
--- a/benches/convert.rs
+++ b/benches/convert.rs
@@ -1,9 +1,8 @@
use criterion::{criterion_group, criterion_main, Bencher, Criterion};
-use half::{
- bfloat::{self, bf16},
- consts, f16,
-};
-use std::{f32, f64};
+use half::prelu... | 1 | 194 | 65 |
1abb9a408f0f78ebc83bfc4e65bbb6cac3c70c2c | Kathryn Long | 2019-10-13T00:30:45 | minor doc link update | diff --git a/src/lib.rs b/src/lib.rs
index 02f047c..f852a67 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -32,7 +32,7 @@
//!
//! The crate uses `#[no_std]` by default, so can be used in embedded environments without using the
//! Rust `std` library. A `std` feature is available, which enables additional utilities usin... | 1 | 2 | 1 |
ec0a3789e369aa332e6cf09c920a6b8b3f19279f | Kathryn Long | 2019-10-12T23:30:11 | use pattern match in classify | diff --git a/src/bfloat.rs b/src/bfloat.rs
index a668fa1..5168f5e 100644
--- a/src/bfloat.rs
+++ b/src/bfloat.rs
@@ -291,20 +291,12 @@ pub fn is_normal(self) -> bool {
pub fn classify(self) -> FpCategory {
let exp = self.0 & 0x7F80u16;
let man = self.0 & 0x007Fu16;
- if exp == 0 {
- ... | 2 | 12 | 28 |
ed17951fea3001ac48c21997d841775d5bdb765a | Kathryn Long | 2019-10-12T23:18:49 | add link so serde in crate doc | diff --git a/src/lib.rs b/src/lib.rs
index 12e9d67..d98aad4 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -27,8 +27,8 @@
//! supports it, the [`slice`] trait conversions will use vectorized SIMD intructions for
//! increased efficiency.
//!
-//! Support for `serde` crate `Serialize` and `Deserialize` traits is provide... | 1 | 3 | 2 |
d83e514cb5065dbf43b11d6a17dbb02a102cdd72 | Kathryn Long | 2019-10-05T06:53:46 | use new core:arch for convert intrinsics | diff --git a/src/lib.rs b/src/lib.rs
index 6f7a153..0bf1843 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -34,7 +34,6 @@
missing_docs,
missing_copy_implementations,
missing_debug_implementations,
- trivial_casts,
trivial_numeric_casts,
unused_extern_crates,
unused_import_braces,
@@ -45,7 ... | 1 | 120 | 34 |
5c0d4e9ab8aeb73f0b6b5a44a1f44fadeeea2f11 | Kathryn Long | 2019-10-06T21:08:52 | code cleanup | diff --git a/Cargo.toml b/Cargo.toml
index e6878b9..ce48603 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -8,6 +8,7 @@ readme = "README.md"
keywords = ["f16", "bfloat16", "no_std"]
license = "MIT/Apache-2.0"
categories = ["no-std", "data-structures", "encoding"]
+edition = "2018"
[badges]
appveyor = { repository =... | 4 | 28 | 34 |
1ef51bd87497f87b3d99654d19850727df7fbb54 | Kathryn Long | 2019-10-06T20:35:30 | add quickcheck tests for conversions | diff --git a/Cargo.toml b/Cargo.toml
index 39c57cf..e6878b9 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -30,6 +30,9 @@ features = ["std", "serde"]
[dev-dependencies]
criterion = "0.3"
+quickcheck = "0.9"
+quickcheck_macros = "0.8"
+rand = "0.7"
[[bench]]
name = "convert"
diff --git a/src/bfloat.rs b/src/bfloat.... | 3 | 65 | 0 |
c39452326bcda26b36598c1a91a70a359a8340d1 | Kathryn Long | 2019-10-06T07:30:12 | add benchmarks | diff --git a/Cargo.toml b/Cargo.toml
index e72013a..39c57cf 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -27,3 +27,10 @@ features = ["derive"]
[package.metadata.docs.rs]
features = ["std", "serde"]
+
+[dev-dependencies]
+criterion = "0.3"
+
+[[bench]]
+name = "convert"
+harness = false
\ No newline at end of file
di... | 2 | 201 | 0 |
18a20b7dd4fdae48159037ce4b7f6bf7500d2961 | Trevor Spiteri | 2019-10-05T14:54:52 | update NaN conversion tests | diff --git a/src/bfloat.rs b/src/bfloat.rs
index b240517..fa1786b 100644
--- a/src/bfloat.rs
+++ b/src/bfloat.rs
@@ -867,11 +867,11 @@ fn test_bf16_consts_from_f64() {
}
#[test]
- fn test_nan_conversion() {
- let nan64 = f64::from_bits(0x7ff0_0000_0000_0001u64);
- let neg_nan64 = f64::from_... | 2 | 80 | 78 |
fccaf7c92334d745258e0a546c39af4de58e1cbe | Trevor Spiteri | 2019-10-05T14:23:44 | all NaN conversions keep sign and set most significant mantissa bit | diff --git a/src/bfloat.rs b/src/bfloat.rs
index aa6e630..b240517 100644
--- a/src/bfloat.rs
+++ b/src/bfloat.rs
@@ -510,16 +510,14 @@ fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> {
}
mod convert {
- use core;
-
pub fn f32_to_bf16(value: f32) -> u16 {
// Convert to raw bytes
l... | 2 | 18 | 13 |
1a00e791cb564064de00caf365fd3db2597bcd38 | Kathryn Long | 2019-10-05T07:59:47 | rustfmt and fix clipy lints on tests | diff --git a/src/bfloat.rs b/src/bfloat.rs
index 7c48068..aa6e630 100644
--- a/src/bfloat.rs
+++ b/src/bfloat.rs
@@ -523,12 +523,12 @@ pub fn f32_to_bf16(value: f32) -> u16 {
}
// round and shift
- let round_bit = 0x0000_8000u32;
- if (x & round_bit) != 0 && (x & (3 * round_bit - 1)) != 0 {
+ ... | 2 | 313 | 85 |
b190f55b29989ff41e6692969607e05d6808a5b4 | Trevor Spiteri | 2019-10-05T07:25:56 | ties round to even when converting f32 to bf16 and f64 to bf16
Also fixes a bug in subnormal rounding when going from f64 to bf16. | diff --git a/src/bfloat.rs b/src/bfloat.rs
index a0a7b10..7c48068 100644
--- a/src/bfloat.rs
+++ b/src/bfloat.rs
@@ -523,7 +523,12 @@ pub fn f32_to_bf16(value: f32) -> u16 {
}
// round and shift
- ((x + 0x0000_8000u32) >> 16) as u16
+ let round_bit = 0x0000_8000u32;
+ if (x & round_bit) != 0 ... | 1 | 94 | 20 |
f923144b1d29028d5c3f716bd2802b356caf4603 | Kathryn Long | 2019-10-05T06:35:47 | Revert "use new core::arch for convert intrinsics"
This reverts commit 1556d148811a7ba93ec3e1788e56fd865a03d056. | diff --git a/src/lib.rs b/src/lib.rs
index cff2639..56c30e6 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -34,6 +34,7 @@
missing_docs,
missing_copy_implementations,
missing_debug_implementations,
+ trivial_casts,
trivial_numeric_casts,
unused_extern_crates,
unused_import_braces,
@@ -44,13... | 1 | 30 | 207 |
8404ff2de000e961983b161f35b4c79a25dc5091 | Kathryn Long | 2019-10-05T06:35:35 | Revert "use macro for feature detection impl"
This reverts commit 064614aba3dcc14ad9868179fb0a5c2a906beabd. | diff --git a/src/lib.rs b/src/lib.rs
index e356fcd..cff2639 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -574,86 +574,148 @@ fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> {
#[allow(dead_code)]
mod convert {
- macro_rules! convert_fn {
- (fn $name:ident($var:ident : $vartype:ty) -> $restype:ty {... | 1 | 116 | 54 |
064614aba3dcc14ad9868179fb0a5c2a906beabd | Kathryn Long | 2019-10-05T04:22:26 | use macro for feature detection impl | diff --git a/src/lib.rs b/src/lib.rs
index cff2639..e356fcd 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -574,148 +574,86 @@ fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> {
#[allow(dead_code)]
mod convert {
- #[inline(always)]
- pub fn f32_to_f16(f: f32) -> u16 {
- // Use CPU feature detecti... | 1 | 54 | 116 |
1556d148811a7ba93ec3e1788e56fd865a03d056 | Kathryn Long | 2019-10-05T03:09:27 | use new core::arch for convert intrinsics | diff --git a/src/lib.rs b/src/lib.rs
index 56c30e6..cff2639 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -34,7 +34,6 @@
missing_docs,
missing_copy_implementations,
missing_debug_implementations,
- trivial_casts,
trivial_numeric_casts,
unused_extern_crates,
unused_import_braces,
@@ -45,7 ... | 1 | 207 | 30 |
962ad5287c66a8d1fbd4be41c666f8cb4c15b520 | Trevor Spiteri | 2019-10-04T22:49:38 | test rounding to nearest with ties to even | diff --git a/src/lib.rs b/src/lib.rs
index 1c9e6fe..d11266b 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1299,4 +1299,84 @@ fn test_mutablility() {
bits[0] = LN_2.to_bits();
assert_eq!(bits, &[LN_2.to_bits()]);
}
+
+ #[test]
+ fn round_to_even_f32() {
+ // smallest positive subnormal... | 1 | 80 | 0 |
e9176238019ca46eac47bbf94738c50cf476d7ac | Trevor Spiteri | 2019-10-04T22:48:47 | ties round to even when converting f16 to f32 and f16 to f64
In conversions from `f32` or `f64` to `f16`, instead of rounding to
nearest with ties rounded away from zero, now ties are rounded to
even. This can be achieved using only one extra mask check for normal
numbers, using a method explained in an inline comment... | diff --git a/src/lib.rs b/src/lib.rs
index 99ec387..1c9e6fe 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -596,33 +596,34 @@ pub fn f16_to_f64(i: u16) -> f64 {
mod convert {
use core;
+ // In the below functions, round to nearest, with ties to even.
+ // Let us call the most significant bit that will be shi... | 1 | 33 | 40 |
4fd30dcb0d7f80e9d1802b8a356f38fb70839c4c | Kathryn Long | 2019-10-04T08:44:05 | fix compile error in tests on std feature | diff --git a/src/bfloat.rs b/src/bfloat.rs
index 438f5e1..799739d 100644
--- a/src/bfloat.rs
+++ b/src/bfloat.rs
@@ -1016,7 +1016,7 @@ fn test_slice_conversions() {
#[test]
#[cfg(feature = "std")]
fn test_vec_conversions() {
- use consts::*;
+ use super::consts::*;
let numbers = ve... | 2 | 2 | 2 |
ba2e02378fdb255a49fdd606f94123c06702f989 | Kathryn Long | 2019-10-04T08:32:35 | code cleanup with clippy | diff --git a/src/bfloat.rs b/src/bfloat.rs
index 7d9c09c..438f5e1 100644
--- a/src/bfloat.rs
+++ b/src/bfloat.rs
@@ -476,30 +476,30 @@ fn ge(&self, other: &bf16) -> bool {
impl FromStr for bf16 {
type Err = ParseFloatError;
fn from_str(src: &str) -> Result<bf16, ParseFloatError> {
- f32::from_str(src)... | 2 | 40 | 39 |
2746649b3a905dbf722cbd1089adde2acafa1ae6 | Kathryn Long | 2019-10-04T06:59:13 | reorganize bfloat module names | diff --git a/src/bfloat.rs b/src/bfloat.rs
index 35aeb95..60e3d14 100644
--- a/src/bfloat.rs
+++ b/src/bfloat.rs
@@ -1,3 +1,8 @@
+//! The bfloat16 floating point format is a truncated 16-bit version of `f32`.
+//!
+//! `bf16` has approximately the same dynamic range as `f32` by having a lower precision than `f16`.
+//!... | 2 | 103 | 95 |
5149c591231b8dcffc4f11aa9e71b33bde68dc1a | Trevor Spiteri | 2019-04-06T21:52:57 | move use of transmute into four tiny functions | diff --git a/src/lib.rs b/src/lib.rs
index 2d205fc..326bb56 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -547,6 +547,31 @@ fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
}
}
+#[cfg(any(test, not(feature = "use-intrinsics")))]
+mod f32_f64_bits {
+ use core::mem;
+
+ #[inline]
+ pub fn f32_from_... | 1 | 51 | 52 |
586330a43d25351c40be68961ea2efdd941f3e0a | Trevor Spiteri | 2019-04-06T21:29:46 | add some tests for constants and fix MAX_10_EXP | diff --git a/src/lib.rs b/src/lib.rs
index 9c7175f..2d205fc 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -63,7 +63,7 @@ pub mod consts {
/// Largest finite `f16` value. `65504`
pub const MAX: f16 = f16(0x7BFF);
/// 16-bit equivalent of `std::f32::MAX_10_EXP`
- pub const MAX_10_EXP: i32 = 5;
+ pub co... | 1 | 63 | 1 |
d691157dbe8a5f12a773b88c02551c5b99a17636 | Trevor Spiteri | 2019-04-06T14:00:28 | add bfloat16 versions: bf16, bconsts, bslice and bvec | diff --git a/src/bfloat.rs b/src/bfloat.rs
new file mode 100644
index 0000000..35aeb95
--- /dev/null
+++ b/src/bfloat.rs
@@ -0,0 +1,1084 @@
+use core::cmp::Ordering;
+use core::fmt::{Debug, Display, Error, Formatter, LowerExp, UpperExp};
+use core::num::{FpCategory, ParseFloatError};
+use core::str::FromStr;
+
+/// The... | 2 | 1,089 | 0 |
6d668c7229631b080e2734f3f2383da2b693f1ec | Trevor Spiteri | 2019-04-06T13:05:27 | make docs.rs document vec module that requires std feature | diff --git a/Cargo.toml b/Cargo.toml
index 942d87d..a712ec8 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -23,4 +23,7 @@ serialize = ["serde"] # Deprecated. Use serde directly.
version = "1.0"
optional = true
default-features = false
-features = ["derive"]
\ No newline at end of file
+features = ["derive"]
+
+[package... | 1 | 4 | 1 |
03e8fe75e1e8ed5fedec94a481f9d557025f6322 | Trevor Spiteri | 2019-04-06T11:50:09 | fix tests that used EPSILON when comparing to 7.1 | diff --git a/src/lib.rs b/src/lib.rs
index a6fd0dc..9c7175f 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1105,7 +1105,8 @@ fn test_f16_to_f32() {
// 7.1 is NOT exactly representable in 16-bit, it's rounded
let f = f16::from_f32(7.1);
let diff = (f.to_f32() - 7.1f32).abs();
- assert!(di... | 1 | 4 | 2 |
823b557cc7be57f47bcbac604de170770dfe083b | Trevor Spiteri | 2019-04-06T11:26:43 | fix some constants
EPSILON = 2^-10, its biased exp is 5, so bits are 5<<10 = 0x1400.
10^5 <= MAX < 10^6, so MAX_10_EXP is 5.
10^-5 <= MIN < 10^-4, so MIN_10_EXP is -4.
MAX_EXP and MIN_EXP are 16, -13, because like C's float.h, std::f32
assumes the significand is in the range 0.5 <= x < 1.0. (The text of
the IEEE-754 ... | diff --git a/src/lib.rs b/src/lib.rs
index 59b1239..a6fd0dc 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -55,7 +55,7 @@ pub mod consts {
/// 16-bit equivalent of `std::f32::DIGITS`
pub const DIGITS: u32 = 3;
/// 16-bit floating point epsilon. `9.7656e-4`
- pub const EPSILON: f16 = f16(0x1700u16);
+ ... | 1 | 7 | 7 |
15638ff235f4a9f11b176180e757d6a7485ad08d | Peter Kloss | 2018-10-03T22:17:24 | elide some lifetimes | diff --git a/src/lib.rs b/src/lib.rs
index a492478..59b1239 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -828,7 +828,7 @@ pub mod slice {
// Which prevents mutating the borrowed `mut [u16]` argument
// As long as the returned `mut [f16]` is borrowed.
#[inline]
- pub fn from_bits_mut<'s>(bits: &'s mut [... | 1 | 4 | 4 |
7205555afc3ff47f320a3b726df6c55f79d5f9eb | johannesvollmer | 2018-09-26T19:05:21 | Fixed documentation and improved comment formatting | diff --git a/src/lib.rs b/src/lib.rs
index 3fed18e..a492478 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -824,9 +824,9 @@ pub mod slice {
use core::slice;
/// Reinterpret a mutable slice of `u16` bits as a mutable slice of `f16` numbers.
- // the transmuted slice has the same life time as the original,
- ... | 1 | 9 | 9 |
90155f3504cff2aaafb735594595387d5dec3212 | johannesvollmer | 2018-09-25T14:31:07 | Added functionality to convert between mutable slices | diff --git a/src/lib.rs b/src/lib.rs
index 793601a..3fed18e 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -818,14 +818,32 @@ pub fn f16_to_f64(i: u16) -> f64 {
}
}
-/// Contains utility functions to convert between slices of u16 bits and f16 numbers.
+/// Contains utility functions to convert between slices of `u... | 1 | 40 | 4 |
a15e157e70f19e6e9c6da2559fea2d39ede10560 | Kathryn Long | 2018-09-03T19:13:10 | remove qualification lint, run rustfmt | diff --git a/src/lib.rs b/src/lib.rs
index 4307d1b..0184fa0 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -22,8 +22,10 @@
//! Rust `std` library. While a `std` feature is available, at present there are no additional
//! changes when the feature is enabled and is merely provided for forward-compatibility.
-#![warn(mi... | 1 | 32 | 16 |
5fd9be187d1603457e28691a50bd770114127d10 | johannesvollmer | 2018-09-02T08:42:43 | Added fully qualified path to `Debug` because it seems like it was not included in the prelude in Rust 1.10.0 | diff --git a/src/lib.rs b/src/lib.rs
index e44b42d..4307d1b 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1196,7 +1196,7 @@ fn test_vec_conversions(){
assert_slice_contents_eq(&to_bits, &bits_cloned);
}
- fn assert_slice_contents_eq<T: PartialEq + Debug>(a: &[T], b: &[T]){
+ fn assert_slice_content... | 1 | 1 | 1 |
861a2b16ad0887c6137ca10c08ddfe5948579006 | johannesvollmer | 2018-09-02T08:36:10 | Removed `assert!` message string to enable building with Rust 1.10.0 and added `#[inline]` to slice conversions | diff --git a/src/lib.rs b/src/lib.rs
index 65262cc..e44b42d 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -828,6 +828,7 @@ pub mod slice {
/// Reinterpret a slice of u16 bits as a slice of f16 numbers.
// the transmuted slice has the same life time as the original
+ #[inline]
pub fn from_bits<'s>(bits... | 1 | 4 | 2 |
5b92d968bfaed2a67d5be97efc03c4f681280a23 | johannesvollmer | 2018-09-01T11:47:03 | Adds utility functions to convert between slices and vectors of u16 bits and f16 numbers, including some simple tests. | diff --git a/src/lib.rs b/src/lib.rs
index 11cc207..65262cc 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -816,6 +816,87 @@ pub fn f16_to_f64(i: u16) -> f64 {
}
}
+/// Contains utility functions to convert between slices of u16 bits and f16 numbers.
+pub mod slice {
+ use super::f16;
+ use core::slice;
+
+ ... | 1 | 125 | 0 |
4da87b20e6146f3b19902c52c6a85ea7dbacb311 | Trevor Spiteri | 2018-08-24T10:32:49 | rename as_bits -> to_bits | diff --git a/src/lib.rs b/src/lib.rs
index 34d79f2..11cc207 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -158,10 +158,17 @@ pub fn from_f64(value: f64) -> f16 {
/// Converts an `f16` into the underlying bit representation.
#[inline]
- pub fn as_bits(self) -> u16 {
+ pub fn to_bits(self) -> u16 {
... | 1 | 8 | 1 |
8815f2b9ad5aba24b1d5151d8932778029ec2e89 | Sebastian Köln | 2018-06-23T00:51:26 | use leading_zeros instead of a loop | diff --git a/src/lib.rs b/src/lib.rs
index 52c4c0b..2cdabbc 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -751,18 +751,10 @@ pub fn f16_to_f32(i: u16) -> f32 {
// Check for subnormals, which will be normalized by adjusting exponent
if half_exp == 0 {
// Calculate how much to adjust the expo... | 1 | 3 | 19 |
2ce18d0d574eeb1033095f1f1e007cb80296c2b1 | Sebastian Köln | 2018-06-23T00:39:04 | add more tests (f32/f64) -> f16 | diff --git a/src/lib.rs b/src/lib.rs
index 26de6ab..52c4c0b 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1015,6 +1015,9 @@ fn test_f16_to_f32() {
assert_eq!(f16::from_bits(0x0000_0001).to_f32(), 2.0f32.powi(-24));
assert_eq!(f16::from_bits(0x0000_0005).to_f32(), 5.0 * 2.0f32.powi(-24));
+ ... | 1 | 6 | 0 |
18e6467b52f821d21a7179d1da5ac5aded63b3bd | Sebastian Köln | 2018-06-23T00:35:48 | hopefully fix subnormals | diff --git a/src/lib.rs b/src/lib.rs
index b6a7bd4..26de6ab 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -725,7 +725,7 @@ pub fn f64_to_f16(value: f64) -> u16 {
pub fn f16_to_f32(i: u16) -> f32 {
// Check for signed zero
if i & 0x7FFFu16 == 0 {
- return unsafe { mem::transmute((i as u32... | 1 | 22 | 14 |
8a7c92e6282318f0f9d73056ca7346a11f8d9518 | PSeitz | 2018-03-13T15:40:32 | pub to_f32 to_f64 | diff --git a/src/lib.rs b/src/lib.rs
index 296a2a9..b6a7bd4 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -167,7 +167,7 @@ pub fn as_bits(self) -> u16 {
/// This conversion is lossless as all 16-bit floating point values can be represented exactly
/// in 32-bit floating point.
#[inline]
- fn to_f32(self... | 1 | 2 | 2 |
cf71f320e51a89784831b6f2805c2c024165d0d3 | Kathryn Long | 2018-01-13T03:41:56 | reformat with latest rustfmt | diff --git a/src/lib.rs b/src/lib.rs
index aaa4b4e..296a2a9 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -22,14 +22,8 @@
//! Rust `std` library. While a `std` feature is available, at present there are no additional
//! changes when the feature is enabled and is merely provided for forward-compatibility.
-#![warn(mi... | 1 | 3 | 9 |
3d45198d6302066568b94517f54f2b3d5c643dd0 | Trevor Spiteri | 2018-01-08T12:03:49 | fix NaN conversion from `f64`, and maintain NaN sign | diff --git a/src/lib.rs b/src/lib.rs
index ecd95f8..f5745d3 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -521,8 +521,6 @@ mod convert {
use core;
use core::mem;
- use super::*;
-
pub fn f32_to_f16(value: f32) -> u16 {
// Convert to raw bytes
let x: u32 = unsafe { mem::transmute(valu... | 1 | 72 | 6 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.