Skip to content

Instantly share code, notes, and snippets.

@gnzlbg
Created April 15, 2016 09:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gnzlbg/4ad70357747d202d4cacf39f8b5afecd to your computer and use it in GitHub Desktop.
Save gnzlbg/4ad70357747d202d4cacf39f8b5afecd to your computer and use it in GitHub Desktop.
/// Primitive number constants
trait PrimNumConstants {
const ZERO: Self;
const ONE: Self;
fn zero() -> Self; // make const?
fn one() -> Self;
}
/// Primitive number information
trait PrimNumInfo {
fn is_signed() -> bool;
fn is_unsigned() -> bool;
fn is_floating_point() -> bool;
fn is_integer() -> bool;
fn bit_width() -> u32;
}
/// Primitive number bounds
trait PrimNumBounds {
fn min_value() -> Self;
fn max_value() -> Self;
fn min_positive_value() -> Self;
fn epsilon() -> Self;
}
/// Primitive number checked arithmetic
trait PrimNumCheckedArithmetic {
fn checked_add(&self, &Self) -> Option<Self>;
fn checked_sub(&self, &Self) -> Option<Self>;
fn checked_div(&self, &Self) -> Option<Self>;
fn checked_mul(&self, &Self) -> Option<Self>;
fn checked_neg(&self, &Self) -> Option<Self>;
}
/// Primitive number unchecked arithmetic
trait PrimNumUncheckedArithmetic {
unsafe fn unchecked_add(&self, &Self) -> Self;
unsafe fn unchecked_sub(&self, &Self) -> Self;
unsafe fn unchecked_div(&self, &Self) -> Self;
unsafe fn unchecked_mul(&self, &Self) -> Self;
unsafe fn unchecked_neg(&self, &Self) -> Self;
}
/// Primitive number total ordering
trait PrimNumTotalOrder {
fn less_than(&self, &Self) -> bool;
fn equal(&self, &Self) -> bool;
}
/// Primitive number partial ordering
trait PrimNumPartialOrder {
fn less_than(&self, &Self) -> bool;
fn equal(&self, &Self) -> bool;
}
/// Primitive number
trait PrimNum
: PrimNumInfo
+ PrimNumBounds
+ PrimNumCheckedArithmetic
+ PrimNumUncheckedArithmetic
{
fn abs(&self) -> Self;
fn abs_sub(&self, &Self) -> Self;
fn signum(&self) -> Self;
fn is_positive(&self) -> Self;
fn is_negative(&self) -> Self;
fn max(&self, &Self) -> &Self;
fn min(&self, &Self) -> &Self;
fn div_rem(&self, &Self) -> (Self, Self);
}
/// Primitive integer
trait PrimInt : PrimNum + PrimNumTotalOrder {
type Signed : PrimInt;
type Unsigned : PrimInt;
fn div_floor(&self, &Self) -> Self;
fn mod_floor(&self, &Self) -> Self;
fn gcd(&self, &Self) -> Self;
fn lcd(&self, &Self) -> Self;
fn is_multiple_of(&self) -> bool;
fn is_even(&self) -> bool;
fn is_odd(&self) -> bool;
fn div_mod_floor(&self, &Self) -> (Self, Self)
fn logical_shr(self, u32) -> Self;
fn logical_shl(self, u32) -> Self;
fn arithmetic_shr(self, u32) -> Self;
fn arithemtic_shl(self, u32) -> Self;
}
/// Primitive bit integer
trait PrimBitInt : PrimInt {
fn count_ones(&self) -> u32;
fn count_zeros(&self) -> u32;
fn leading_zeros(&self) -> u32;
fn trailing_zeros(&self) -> u32;
fn leading_ones(&self) -> u32;
fn trailing_ones(&self) -> u32;
fn rotate_left(&self, &u32) -> Self;
fn rotate_right(&self, &u32) -> Self;
fn signed_shr(&self, &u32) -> Self;
fn signed_shl(&self, &u32) -> Self;
fn unsigned_shr(&self, &u32) -> Self;
fn unsigned_shl(&self, &u32) -> Self;
fn swap_bytes(&self) -> Self;
fn from_be(&self) -> Self;
fn from_le(&self) -> Self;
fn to_be(&self) -> Self;
fn to_le(&self) -> Self;
fn ipow(self, mut u32) -> Self;
fn to_unsigned(&self) -> Self::Unsigned;
fn to_signed(&self) -> Self::Unsigned;
fn parity(&self) -> u32;
fn reset_least_significant_one(self) -> Self;
fn set_least_significant_zero(self) -> Self;
fn isolate_least_significant_one(self) -> Self;
fn isolate_least_significant_zero(self) -> Self;
fn reset_trailing_ones(self) -> Self;
fn reset_trailing_zeros(self) -> Self;
fn mask_trailing_zeros(self) -> Self;
fn mask_trailing_ones(self) -> Self;
fn mask_trailing_zeros_and_least_significant_one(self) -> Self;
fn mask_trailing_ones_and_least_significant_zero(self) -> Self;
fn reverse_bit_groups(self, u32, u32) -> Self;
fn reverse_bits(self) -> Self;
fn reverse_bit_pairs(self) -> Self;
fn reverse_bit_nibbles(self) -> Self;
fn reverse_byte_groups(self, u32, u32) -> Self;
fn reverse_bytes(self) -> Self;
fn set_bit(self, bit: u32) -> Self;
fn reset_bit(self, bit: u32) -> Self;
fn flip_bit(self, bit: u32) -> Self;
fn test_bit(self, bit: u32) -> bool;
fn reset_bits_geq(self, bit: u32) -> Self;
fn reset_bits_leq(self, bit: u32) -> Self;
fn set_bits_geq(self, bit: u32) -> Self;
fn set_bits_leq(self, bit: u32) -> Self;
fn flip_bits_geq(self, bit: u32) -> Self;
fn flip_bits_leq(self, bit: u32) -> Self;
fn is_pow2(self) -> bool;
fn ceil_pow2(self)-> Self;
fn floor_pow2(self) -> Self;
fn is_aligned(self, alignment: u32) -> bool;
fn align_up(self, alignment: u32) -> Self;
fn align_down(self, alignment: u32) -> Self;
fn outer_perfect_shuffle(self) -> Self;
fn outer_perfect_unshuffle(self) -> Self;
fn inner_perfect_shuffle(self) -> Self;
fn inner_perfect_unshuffle(self) -> Self;
fn parallel_bits_deposit(self, Self) -> Self;
fn parallel_bits_extract(self, Self) -> Self;
}
/// Primitive signed integer (implemented only for signed ints)
trait PrimSignedInt : PrimBitInt {
}
/// Primitive unsigned integer (implemented only for unsigned ints)
trait PrimUnsignedInt : PrimBitInt {
}
/// Primitive float
trait PrimFloat : PrimNum + PrimNumPartialOrder {
fn rounding_error() -> Self;
fn positive_infinity() -> Self;
fn negative_infinity() -> Self;
fn quiet_nan() -> Self;
fn signaling_nan() -> Self;
fn nan() -> Self;
fn is_nan(&self) -> bool;
fn is_quiet_nan(&self) -> bool;
fn is_signaling_nan(&self) -> bool;
fn positive_zero() -> Self;
fn negative_zero() -> Self;
fn is_infinite(&self) -> bool;
fn is_finite(&self) -> bool;
fn is_positive_infinite(&self) -> bool;
fn is_negative_infinite(&self) -> bool;
fn is_normal(&self) -> bool;
fn classify(&self) -> FpClass; // Normal, sub-normal, zero, infinite, nan
fn floor(&self) -> Self;
fn ceil(&self) -> Self;
fn round(&self) -> Self;
fn truncate(&self) -> Self;
fn fractional(&self) -> Self;
fn mul_add(&self, &Self, &Self) -> Self;
fn reciprocal(&self) -> Self;
fn ipow(&self, &i32) -> Self;
fn upow(&self, &u32) -> Self;
fn pow(&self, &Self) -> Self;
fn sqrt(&self) -> Self;
fn exp(&self) -> Self;
fn exp2(&self) -> Self;
fn ln(&self) -> Self;
fn log(&self, Self) -> Self;
fn log2(&self) -> Self;
fn log10(&self) -> Self;
fn cbrt(&self) -> Self;
fn hypot(&self, &Self) -> Self;
fn sin(&self) -> Self;
fn cos(&self) -> Self;
fn tan(&self) -> Self;
fn asin(&self) -> Self;
fn acos(&self) -> Self;
fn atan(&self) -> Self;
fn atan2(&self) -> Self;
fn sin_cos(&self) -> Self;
fn exp_m1(&self) -> Self;
fn ln_1p(&self) -> Self;
fn sinh(&self) -> Self;
fn cosh(&self) -> Self;
fn tanh(&self) -> Self;
fn asinh(&self) -> Self;
fn acosh(&self) -> Self;
fn atanh(&self) -> Self;
fn integer_decode(&self) -> (u64, i16, i8);
fn fdim(&self, &Self) -> Self; // fdim C++11
fn erf(&self) -> Self;
fn erfc(&self) -> Self;
fn gamma(&self) -> Self;
fn times_pow2(&self, Self) -> Self;
fn times_pow_radix(&self, Self) -> Self;
fn ilog_base(&self) -> i32;
fn log_base(&self) -> Self;
fn next_after(&self, &Self) -> Self;
fn next_toward(&self, &Self) -> Self;
fn is_unordered(&self, &Self) -> bool;
// From Special Mathematical Functions
fn beta(&self, &Self) -> Self;
fn riemann_zeta(&self, &Self) -> Self;
// Elliptic integrals
fn elliptic_int_1st_complete(&self) -> Self;
fn elliptic_int_2nd_complete(&self) -> Self;
fn elliptic_int_3rd_complete(&self) -> Self;
fn elliptic_int_1st_incomplete(&self) -> Self;
fn elliptic_int_2nd_incomplete(&self) -> Self;
fn elliptic_int_3rd_incomplete(&self) -> Self;
fn exp_int(&self, ...) -> Self;
// Cylindrical bessel functions
fn cylindrical_bessel_1st(&self, ) -> Self;
fn cylindrical_bessel_regular_modified(&self, ) -> Self;
fn cylindrical_bessel_irregular_modified(&self, ) -> Self;
fn cylindrical_bessel_neumann(&self, ) -> Self;
// Spherical functions
fn spherical_bessel_1st(&self, ) -> Self;
fn spherical_associated_legendre(&self, ) -> Self;
fn spherical_neumann(&self, ) -> Self;
// Polynomials
fn associated_laguerre(u32, u32) -> Self;
fn associated_legendre(u32, u32) -> Self;
fn hermite(&self, ...) -> Self;
fn legendre(&self, ...) -> Self;
fn laguerre(&self, ...) -> Self;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment