Skip to content

Commit

Permalink
Make a cosmetic adjustment
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanUkhov committed Aug 8, 2024
1 parent ba55301 commit 3e95532
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 62 deletions.
2 changes: 0 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ extern crate alloc;
mod beta;
mod error;
mod gamma;
#[cfg_attr(feature = "no_std", path = "primitive/extrinsic.rs")]
#[cfg_attr(not(feature = "no_std"), path = "primitive/intrinsic.rs")]
mod primitive;

pub use beta::Beta;
Expand Down
30 changes: 0 additions & 30 deletions src/primitive/extrinsic.rs
Original file line number Diff line number Diff line change
@@ -1,33 +1,3 @@
macro_rules! declare {
($(($name:ident, $f32:expr, $f64:expr, ($($argument:ident: $type_outer:ty as $type_inner:ty),*) -> $return:ty),)*) => {
/// Primitive functions.
pub trait Primitive: Sized {
const PI: Self;
$(fn $name(self, $($argument: $type_outer),*) -> $return;)*
}
}
}

macro_rules! implement {
($(($name:ident, $f32:expr, $f64:expr, ($($argument:ident: $type_outer:ty as $type_inner:ty),*) -> $return:ty),)*) => {
impl Primitive for f32 {
const PI: Self = core::f32::consts::PI;
$(implement! { @method $name, $f32, ($($argument: $type_outer as $type_inner),*) -> $return })*
}

impl Primitive for f64 {
const PI: Self = core::f64::consts::PI;
$(implement! { @method $name, $f64, ($($argument: $type_outer as $type_inner),*) -> $return })*
}
};
(@method $name:ident, $function:expr, ($($argument:ident: $type_outer:ty as $type_inner:ty),*) -> $return:ty) => {
#[inline(always)]
fn $name(self, $($argument: $type_outer),*) -> $return {
$function(self, $($argument as $type_inner),*)
}
}
}

macro_rules! run {
($macro: ident) => {
$macro! {
Expand Down
30 changes: 0 additions & 30 deletions src/primitive/intrinsic.rs
Original file line number Diff line number Diff line change
@@ -1,33 +1,3 @@
macro_rules! declare {
($(($name:ident, $f32:expr, $f64:expr, ($($argument:ident: $type_outer:ty as $type_inner:ty),*) -> $return:ty),)*) => {
/// Primitive functions.
pub trait Primitive: Sized {
const PI: Self;
$(fn $name(self, $($argument: $type_outer),*) -> $return;)*
}
}
}

macro_rules! implement {
($(($name:ident, $f32:expr, $f64:expr, ($($argument:ident: $type_outer:ty as $type_inner:ty),*) -> $return:ty),)*) => {
impl Primitive for f32 {
const PI: Self = core::f32::consts::PI;
$(implement! { @method $name, $f32, ($($argument: $type_outer as $type_inner),*) -> $return })*
}

impl Primitive for f64 {
const PI: Self = core::f64::consts::PI;
$(implement! { @method $name, $f64, ($($argument: $type_outer as $type_inner),*) -> $return })*
}
};
(@method $name:ident, $function:expr, ($($argument:ident: $type_outer:ty as $type_inner:ty),*) -> $return:ty) => {
#[inline(always)]
fn $name(self, $($argument: $type_outer),*) -> $return {
$function(self, $($argument as $type_inner),*)
}
}
}

macro_rules! run {
($macro: ident) => {
$macro! {
Expand Down
35 changes: 35 additions & 0 deletions src/primitive/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
macro_rules! declare {
($(($name:ident, $f32:expr, $f64:expr, ($($argument:ident: $type_outer:ty as $type_inner:ty),*) -> $return:ty),)*) => {
/// Primitive functions.
pub trait Primitive: Sized {
const PI: Self;
$(fn $name(self, $($argument: $type_outer),*) -> $return;)*
}
}
}

macro_rules! implement {
($(($name:ident, $f32:expr, $f64:expr, ($($argument:ident: $type_outer:ty as $type_inner:ty),*) -> $return:ty),)*) => {
impl Primitive for f32 {
const PI: Self = core::f32::consts::PI;
$(implement! { @method $name, $f32, ($($argument: $type_outer as $type_inner),*) -> $return })*
}

impl Primitive for f64 {
const PI: Self = core::f64::consts::PI;
$(implement! { @method $name, $f64, ($($argument: $type_outer as $type_inner),*) -> $return })*
}
};
(@method $name:ident, $function:expr, ($($argument:ident: $type_outer:ty as $type_inner:ty),*) -> $return:ty) => {
#[inline(always)]
fn $name(self, $($argument: $type_outer),*) -> $return {
$function(self, $($argument as $type_inner),*)
}
}
}

#[cfg_attr(feature = "no_std", path = "extrinsic.rs")]
#[cfg_attr(not(feature = "no_std"), path = "intrinsic.rs")]
mod implementation;

pub use implementation::Primitive;

0 comments on commit 3e95532

Please sign in to comment.