Compare commits
11 Commits
truncate-a
...
to_float2
Author | SHA1 | Date | |
---|---|---|---|
cab6790f00 | |||
2045d8047a | |||
fa547050e2 | |||
64e44846aa | |||
0d05540a6b | |||
9b3dde66bd | |||
a65eef3609 | |||
c4a2778af1 | |||
46bb2bac4e | |||
c6b4cc29b8 | |||
9a7ebb0f0a |
2
fixed_wide/Cargo.lock
generated
2
fixed_wide/Cargo.lock
generated
@ -16,7 +16,7 @@ checksum = "50202def95bf36cb7d1d7a7962cea1c36a3f8ad42425e5d2b71d7acb8041b5b8"
|
||||
|
||||
[[package]]
|
||||
name = "fixed_wide"
|
||||
version = "0.1.0"
|
||||
version = "0.1.1"
|
||||
dependencies = [
|
||||
"arrayvec",
|
||||
"bnum",
|
||||
|
@ -1,7 +1,11 @@
|
||||
[package]
|
||||
name = "fixed_wide"
|
||||
version = "0.1.0"
|
||||
version = "0.1.1"
|
||||
edition = "2021"
|
||||
repository = "https://git.itzana.me/StrafesNET/fixed_wide_vectors"
|
||||
license = "MIT OR Apache-2.0"
|
||||
description = "Fixed point numbers with optional widening Mul operator."
|
||||
authors = ["Rhys Lloyd <krakow20@gmail.com>"]
|
||||
|
||||
[features]
|
||||
default=[]
|
||||
@ -13,4 +17,4 @@ zeroes=["dep:arrayvec"]
|
||||
bnum = "0.12.0"
|
||||
arrayvec = { version = "0.7.6", optional = true }
|
||||
paste = "1.0.15"
|
||||
ratio_ops = { path = "../ratio_ops", optional = true }
|
||||
ratio_ops = { version = "0.1.0", path = "../ratio_ops", registry = "strafesnet", optional = true }
|
||||
|
@ -65,19 +65,27 @@ impl<const F:usize> Fixed<1,F>{
|
||||
}
|
||||
#[inline]
|
||||
pub const fn to_raw(self)->i64{
|
||||
self.to_bits().to_bits().digits()[0] as i64
|
||||
let &[digit]=self.to_bits().to_bits().digits();
|
||||
digit as i64
|
||||
}
|
||||
}
|
||||
|
||||
impl<const N:usize,const F:usize,T> From<T> for Fixed<N,F>
|
||||
where
|
||||
BInt<N>:From<T>
|
||||
{
|
||||
#[inline]
|
||||
fn from(value:T)->Self{
|
||||
Self::from_bits(BInt::<{N}>::from(value)<<F as u32)
|
||||
}
|
||||
macro_rules! impl_from {
|
||||
($($from:ty),*)=>{
|
||||
$(
|
||||
impl<const N:usize,const F:usize> From<$from> for Fixed<N,F>{
|
||||
#[inline]
|
||||
fn from(value:$from)->Self{
|
||||
Self::from_bits(BInt::<{N}>::from(value)<<F as u32)
|
||||
}
|
||||
}
|
||||
)*
|
||||
};
|
||||
}
|
||||
impl_from!(
|
||||
u8,u16,u32,u64,u128,usize,
|
||||
i8,i16,i32,i64,i128,isize
|
||||
);
|
||||
|
||||
impl<const N:usize,const F:usize> PartialEq for Fixed<N,F>{
|
||||
#[inline]
|
||||
@ -138,50 +146,55 @@ impl<const N:usize,const F:usize> std::iter::Sum for Fixed<N,F>{
|
||||
}
|
||||
}
|
||||
|
||||
const fn signed_shift(lhs:u64,rhs:i32)->u64{
|
||||
if rhs.is_negative(){
|
||||
lhs>>-rhs
|
||||
}else{
|
||||
lhs<<rhs
|
||||
}
|
||||
#[derive(Debug,Eq,PartialEq)]
|
||||
pub enum FloatFromFixedError{
|
||||
Overflow,
|
||||
Underflow,
|
||||
}
|
||||
macro_rules! impl_into_float {
|
||||
( $output: ty, $unsigned:ty, $exponent_bits:expr, $mantissa_bits:expr ) => {
|
||||
impl<const N:usize,const F:usize> Into<$output> for Fixed<N,F>{
|
||||
impl<const N:usize,const F:usize> TryInto<$output> for Fixed<N,F>{
|
||||
type Error=FloatFromFixedError;
|
||||
#[inline]
|
||||
fn into(self)->$output{
|
||||
fn try_into(self)->Result<$output,FloatFromFixedError>{
|
||||
const DIGIT_SHIFT:u32=6;//Log2[64]
|
||||
// SBBB BBBB
|
||||
// 1001 1110 0000 0000
|
||||
let sign=if self.bits.is_negative(){(1 as $unsigned)<<(<$unsigned>::BITS-1)}else{0};
|
||||
let unsigned=self.bits.unsigned_abs();
|
||||
let most_significant_bit=unsigned.bits();
|
||||
let exp=if unsigned.is_zero(){
|
||||
0
|
||||
}else{
|
||||
let msb=most_significant_bit as $unsigned;
|
||||
let _127=((1 as $unsigned)<<($exponent_bits-1))-1;
|
||||
let msb_offset=msb+_127-1-F as $unsigned;
|
||||
msb_offset<<($mantissa_bits-1)
|
||||
};
|
||||
let digits=unsigned.digits();
|
||||
let digit_index=most_significant_bit>>DIGIT_SHIFT;
|
||||
let digit=digits[digit_index as usize];
|
||||
//How many bits does the mantissa take from this digit
|
||||
let take_bits=most_significant_bit-(digit_index<<DIGIT_SHIFT);
|
||||
let rest_of_mantissa=$mantissa_bits as i32-(take_bits as i32);
|
||||
let mut unmasked_mant=signed_shift(digit,rest_of_mantissa) as $unsigned;
|
||||
if 0<rest_of_mantissa&&digit_index!=0{
|
||||
//take the next digit down and shove some of its bits onto the bottom of the mantissa
|
||||
let digit=digits[digit_index as usize-1];
|
||||
let take_bits=most_significant_bit-((digit_index-1)<<DIGIT_SHIFT);
|
||||
let rest_of_mantissa=$mantissa_bits as i32-(take_bits as i32);
|
||||
let unmasked_mant2=signed_shift(digit,rest_of_mantissa) as $unsigned;
|
||||
unmasked_mant|=unmasked_mant2;
|
||||
if self.is_zero(){
|
||||
return Ok(0.0);
|
||||
}
|
||||
let mant=unmasked_mant&((1 as $unsigned)<<($mantissa_bits-1))-1;
|
||||
let bits=sign|exp|mant;
|
||||
<$output>::from_bits(bits)
|
||||
let unsigned=self.bits.unsigned_abs();
|
||||
println!("unsigned={unsigned}");
|
||||
let most_significant_bit=unsigned.bits() as usize;
|
||||
println!("most_significant_bit={most_significant_bit}");
|
||||
let digit_index=most_significant_bit.saturating_sub(1)>>DIGIT_SHIFT;
|
||||
println!("digit_index={digit_index}");
|
||||
let digits=unsigned.digits();
|
||||
let hi=digits[digit_index];
|
||||
println!("hi={hi}");
|
||||
let mut _128=(hi as u128)<<64;
|
||||
println!("_128={_128}");
|
||||
if digit_index!=0{
|
||||
let lo=digits[digit_index];
|
||||
println!("lo={lo}");
|
||||
_128|=lo as u128;
|
||||
}
|
||||
let bits_informant=(_128 as $output).to_bits();
|
||||
println!("bits_informant={bits_informant}");
|
||||
let exp_informant=((bits_informant>>($mantissa_bits-1))&((1<<$exponent_bits)-1));
|
||||
println!("exp_informant={exp_informant}");
|
||||
let exp=(exp_informant+((digit_index as $unsigned)<<DIGIT_SHIFT))
|
||||
.checked_sub(F as $unsigned+64)
|
||||
.ok_or(FloatFromFixedError::Underflow)?;
|
||||
println!("exp={exp}");
|
||||
if exp&!((1<<$exponent_bits)-1)!=0{
|
||||
return Err(FloatFromFixedError::Overflow);
|
||||
}
|
||||
let sign=(self.bits.is_negative() as $unsigned)<<(<$unsigned>::BITS-1);
|
||||
println!("sign={sign}");
|
||||
let mant=bits_informant&((1 as $unsigned<<($mantissa_bits-1))-1);
|
||||
println!("mant={mant}");
|
||||
let bits=sign|exp<<($mantissa_bits-1)|mant;
|
||||
println!("bits={bits}");
|
||||
Ok(<$output>::from_bits(bits))
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -189,10 +202,106 @@ macro_rules! impl_into_float {
|
||||
impl_into_float!(f32,u32,8,24);
|
||||
impl_into_float!(f64,u64,11,53);
|
||||
|
||||
#[derive(Debug,Eq,PartialEq)]
|
||||
pub enum FixedFromFloatError{
|
||||
Nan,
|
||||
Infinite,
|
||||
Overflow,
|
||||
Underflow,
|
||||
}
|
||||
impl FixedFromFloatError{
|
||||
pub fn underflow_to_zero<const N:usize,const F:usize>(self)->Result<Fixed<N,F>,Self>{
|
||||
match self{
|
||||
FixedFromFloatError::Underflow=>Ok(Fixed::ZERO),
|
||||
_=>Err(self),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct FloatInfo{
|
||||
sign:bool,
|
||||
digit_index:usize,
|
||||
bits:[u64;2],
|
||||
}
|
||||
|
||||
macro_rules! impl_from_float {
|
||||
( $input: ty, $unsigned: ty, $exponent_bits:expr, $mantissa_bits:expr, $exp_bias:expr ) => {
|
||||
impl<const N:usize,const F:usize> TryFrom<$input> for Fixed<N,F>{
|
||||
type Error=FixedFromFloatError;
|
||||
#[inline]
|
||||
fn try_from(value:$input)->Result<Self,Self::Error>{
|
||||
match value.classify(){
|
||||
std::num::FpCategory::Nan=>Err(FixedFromFloatError::Nan),
|
||||
std::num::FpCategory::Infinite=>Err(FixedFromFloatError::Infinite),
|
||||
std::num::FpCategory::Zero=>Ok(Self::ZERO),
|
||||
std::num::FpCategory::Subnormal
|
||||
|std::num::FpCategory::Normal
|
||||
=>{
|
||||
fn to_float_info<const F:usize>(f:$input)->Option<FloatInfo>{
|
||||
const DIGIT_SHIFT:u32=6;
|
||||
let bits=f.to_bits();
|
||||
//extract exponent, add fractional offset
|
||||
//usize is used to calculate digit_index. exp_cycle must be at least 8 bits so 32 bits is fine
|
||||
let exp=((bits>>($mantissa_bits-1)) as usize&((1<<$exponent_bits)-1))+F;
|
||||
//if it's less than zero, that's a conversion underflow.
|
||||
let exp_bias=exp.checked_sub($exp_bias)?;
|
||||
//cycle the exponent to keep the top bit of the mantissa within the hi digit
|
||||
let exp_cycle=exp_bias.rem_euclid(64).overflowing_add($exp_bias+64).0;
|
||||
let out_bits=
|
||||
bits
|
||||
//remove (mask) sign bit and exponent
|
||||
&((1 as $unsigned<<($mantissa_bits-1))-1)
|
||||
//write exponent
|
||||
|((exp_cycle as $unsigned)<<($mantissa_bits-1));
|
||||
//ready to convert
|
||||
let _128=<$input>::from_bits(out_bits) as u128;
|
||||
Some(FloatInfo{
|
||||
sign:f.is_sign_negative(),
|
||||
//digit_index is where the hi digit should end up in a fixed point number
|
||||
digit_index:exp_bias>>DIGIT_SHIFT,
|
||||
bits:[_128 as u64,(_128>>64) as u64],
|
||||
})
|
||||
}
|
||||
|
||||
let FloatInfo{
|
||||
sign,
|
||||
digit_index,
|
||||
bits:[lo,hi],
|
||||
}=to_float_info::<F>(value)
|
||||
.ok_or(FixedFromFloatError::Underflow)?;
|
||||
|
||||
let mut digits=[0u64;N];
|
||||
let digit=digits.get_mut(digit_index)
|
||||
.ok_or(FixedFromFloatError::Overflow)?;
|
||||
*digit=hi;
|
||||
|
||||
if digit_index!=0{
|
||||
//if digit_index exists, so does digit_index-1
|
||||
digits[digit_index-1]=lo;
|
||||
}
|
||||
|
||||
let bits=BInt::from_bits(bnum::BUint::from_digits(digits));
|
||||
if bits.is_negative()&&!(sign&&bits==BInt::MIN){
|
||||
return Err(FixedFromFloatError::Overflow);
|
||||
}
|
||||
Ok(if sign{
|
||||
Self::from_bits(bits.overflowing_neg().0)
|
||||
}else{
|
||||
Self::from_bits(bits)
|
||||
})
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
impl_from_float!(f32,u32,8,24,127);
|
||||
impl_from_float!(f64,u64,11,53,1023);
|
||||
|
||||
impl<const N:usize,const F:usize> core::fmt::Display for Fixed<N,F>{
|
||||
#[inline]
|
||||
fn fmt(&self,f:&mut core::fmt::Formatter)->Result<(),core::fmt::Error>{
|
||||
let float:f32=(*self).into();
|
||||
let float:f32=(*self).try_into().unwrap();
|
||||
core::write!(f,"{:.3}",float)
|
||||
}
|
||||
}
|
||||
|
@ -10,31 +10,86 @@ fn you_can_add_numbers(){
|
||||
#[test]
|
||||
fn to_f32(){
|
||||
let a=I256F256::from(1)>>2;
|
||||
let f:f32=a.into();
|
||||
let f:f32=a.try_into().unwrap();
|
||||
assert_eq!(f,0.25f32);
|
||||
let f:f32=(-a).into();
|
||||
let f:f32=(-a).try_into().unwrap();
|
||||
assert_eq!(f,-0.25f32);
|
||||
let a=I256F256::from(0);
|
||||
let f:f32=(-a).into();
|
||||
let f:f32=a.try_into().unwrap();
|
||||
assert_eq!(f,0f32);
|
||||
let a=I256F256::from(237946589723468975i64)<<32;
|
||||
let f:f32=a.into();
|
||||
assert_eq!(f,237946589723468975f32*2.0f32.powi(32));
|
||||
let a=I256F256::from(237946589723468975i64)<<16;
|
||||
let f:f32=a.try_into().unwrap();
|
||||
assert_eq!(f,237946589723468975f32*2.0f32.powi(16));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn to_f64(){
|
||||
let a=I256F256::from(1)>>2;
|
||||
let f:f64=a.into();
|
||||
let f:f64=a.try_into().unwrap();
|
||||
assert_eq!(f,0.25f64);
|
||||
let f:f64=(-a).into();
|
||||
let f:f64=(-a).try_into().unwrap();
|
||||
assert_eq!(f,-0.25f64);
|
||||
let a=I256F256::from(0);
|
||||
let f:f64=(-a).into();
|
||||
let f:f64=(-a).try_into().unwrap();
|
||||
assert_eq!(f,0f64);
|
||||
let a=I256F256::from(237946589723468975i64)<<32;
|
||||
let f:f64=a.into();
|
||||
assert_eq!(f,237946589723468975f64*2.0f64.powi(32));
|
||||
let a=I256F256::from(237946589723468975i64)<<16;
|
||||
let f:f64=a.try_into().unwrap();
|
||||
assert_eq!(f,237946589723468975f64*2.0f64.powi(16));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_f32(){
|
||||
let a=I256F256::from(1)>>2;
|
||||
let b:Result<I256F256,_>=0.25f32.try_into();
|
||||
assert_eq!(b,Ok(a));
|
||||
let a=I256F256::from(-1)>>2;
|
||||
let b:Result<I256F256,_>=(-0.25f32).try_into();
|
||||
assert_eq!(b,Ok(a));
|
||||
let a=I256F256::from(0);
|
||||
let b:Result<I256F256,_>=0.try_into();
|
||||
//test float mantissa spread across digit boundary
|
||||
//16 is within the 24 bits of float precision
|
||||
assert_eq!(b,Ok(a));
|
||||
let a=I256F256::from(0b101011110101001010101010000000000000000000000000000i64)<<16;
|
||||
let b:Result<I256F256,_>=(0b101011110101001010101010000000000000000000000000000u64 as f32*2.0f32.powi(16)).try_into();
|
||||
assert_eq!(b,Ok(a));
|
||||
//I32F32::MAX into f32 is truncated into this value
|
||||
let a=I32F32::raw(0b111111111111111111111111000000000000000000000000000000000000000i64);
|
||||
let b:Result<I32F32,_>=TryInto::<f32>::try_into(I32F32::MAX).unwrap().try_into();
|
||||
assert_eq!(b,Ok(a));
|
||||
//I32F32::MIN hits a special case since it's not representable as a positive signed integer
|
||||
let a=I32F32::MIN;
|
||||
let b:Result<I32F32,_>=TryInto::<f32>::try_into(I32F32::MIN).unwrap().try_into();
|
||||
assert_eq!(b,Ok(a));
|
||||
let b:Result<I32F32,_>=TryInto::<f32>::try_into(I32F32::MIN.fix_2()+(I32F32::MIN>>1).fix_2()).unwrap().try_into();
|
||||
assert_eq!(b,Err(crate::fixed::FixedFromFloatError::Overflow));
|
||||
let b:Result<I32F32,_>=TryInto::<f32>::try_into(-I32F32::MIN.fix_2()).unwrap().try_into();
|
||||
assert_eq!(b,Err(crate::fixed::FixedFromFloatError::Overflow));
|
||||
let b:Result<I32F32,_>=f32::MIN_POSITIVE.try_into();
|
||||
assert_eq!(b,Err(crate::fixed::FixedFromFloatError::Underflow));
|
||||
//test many cases
|
||||
for i in 0..64{
|
||||
let a=crate::fixed::Fixed::<2,64>::raw_digit(0b111111111111111111111111000000000000000000000000000000000000000i64)<<i;
|
||||
let f:f32=a.try_into().unwrap();
|
||||
let b:Result<crate::fixed::Fixed<2,64>,_>=f.try_into();
|
||||
assert_eq!(b,Ok(a));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_f64(){
|
||||
let a=I256F256::from(1)>>2;
|
||||
let b:Result<I256F256,_>=0.25f64.try_into();
|
||||
assert_eq!(b,Ok(a));
|
||||
let a=I256F256::from(-1)>>2;
|
||||
let b:Result<I256F256,_>=(-0.25f64).try_into();
|
||||
assert_eq!(b,Ok(a));
|
||||
let a=I256F256::from(0);
|
||||
let b:Result<I256F256,_>=0.try_into();
|
||||
assert_eq!(b,Ok(a));
|
||||
let a=I256F256::from(0b101011110101001010101010000000000000000000000000000i64)<<16;
|
||||
let b:Result<I256F256,_>=(0b101011110101001010101010000000000000000000000000000u64 as f64*2.0f64.powi(16)).try_into();
|
||||
assert_eq!(b,Ok(a));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
2
linear_ops/Cargo.lock
generated
2
linear_ops/Cargo.lock
generated
@ -10,7 +10,7 @@ checksum = "50202def95bf36cb7d1d7a7962cea1c36a3f8ad42425e5d2b71d7acb8041b5b8"
|
||||
|
||||
[[package]]
|
||||
name = "fixed_wide"
|
||||
version = "0.1.0"
|
||||
version = "0.1.1"
|
||||
dependencies = [
|
||||
"bnum",
|
||||
"paste",
|
||||
|
@ -2,6 +2,10 @@
|
||||
name = "linear_ops"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
repository = "https://git.itzana.me/StrafesNET/fixed_wide_vectors"
|
||||
license = "MIT OR Apache-2.0"
|
||||
description = "Vector/Matrix operations using trait bounds."
|
||||
authors = ["Rhys Lloyd <krakow20@gmail.com>"]
|
||||
|
||||
[features]
|
||||
default=["named-fields","fixed-wide"]
|
||||
@ -10,9 +14,9 @@ fixed-wide=["dep:fixed_wide","dep:paste"]
|
||||
deferred-division=["dep:ratio_ops"]
|
||||
|
||||
[dependencies]
|
||||
ratio_ops = { path = "../ratio_ops", optional = true }
|
||||
fixed_wide = { path = "../fixed_wide", optional = true }
|
||||
ratio_ops = { version = "0.1.0", path = "../ratio_ops", registry = "strafesnet", optional = true }
|
||||
fixed_wide = { version = "0.1.0", path = "../fixed_wide", registry = "strafesnet", optional = true }
|
||||
paste = { version = "1.0.15", optional = true }
|
||||
|
||||
[dev-dependencies]
|
||||
fixed_wide = { path = "../fixed_wide", features = ["wide-mul"] }
|
||||
fixed_wide = { version = "0.1.0", path = "../fixed_wide", registry = "strafesnet", features = ["wide-mul"] }
|
||||
|
176
linear_ops/LICENSE-APACHE
Normal file
176
linear_ops/LICENSE-APACHE
Normal file
@ -0,0 +1,176 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
23
linear_ops/LICENSE-MIT
Normal file
23
linear_ops/LICENSE-MIT
Normal file
@ -0,0 +1,23 @@
|
||||
Permission is hereby granted, free of charge, to any
|
||||
person obtaining a copy of this software and associated
|
||||
documentation files (the "Software"), to deal in the
|
||||
Software without restriction, including without
|
||||
limitation the rights to use, copy, modify, merge,
|
||||
publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software
|
||||
is furnished to do so, subject to the following
|
||||
conditions:
|
||||
|
||||
The above copyright notice and this permission notice
|
||||
shall be included in all copies or substantial portions
|
||||
of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
|
||||
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
||||
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
|
||||
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
|
||||
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
@ -2,5 +2,9 @@
|
||||
name = "ratio_ops"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
repository = "https://git.itzana.me/StrafesNET/fixed_wide_vectors"
|
||||
license = "MIT OR Apache-2.0"
|
||||
description = "Ratio operations using trait bounds for avoiding division like the plague."
|
||||
authors = ["Rhys Lloyd <krakow20@gmail.com>"]
|
||||
|
||||
[dependencies]
|
||||
|
176
ratio_ops/LICENSE-APACHE
Normal file
176
ratio_ops/LICENSE-APACHE
Normal file
@ -0,0 +1,176 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
23
ratio_ops/LICENSE-MIT
Normal file
23
ratio_ops/LICENSE-MIT
Normal file
@ -0,0 +1,23 @@
|
||||
Permission is hereby granted, free of charge, to any
|
||||
person obtaining a copy of this software and associated
|
||||
documentation files (the "Software"), to deal in the
|
||||
Software without restriction, including without
|
||||
limitation the rights to use, copy, modify, merge,
|
||||
publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software
|
||||
is furnished to do so, subject to the following
|
||||
conditions:
|
||||
|
||||
The above copyright notice and this permission notice
|
||||
shall be included in all copies or substantial portions
|
||||
of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
|
||||
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
||||
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
|
||||
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
|
||||
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
Reference in New Issue
Block a user