-
Notifications
You must be signed in to change notification settings - Fork 98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a generic helper over f32/f64 #275
Add a generic helper over f32/f64 #275
Conversation
Are you using this on an embedded target? Otherwise I see no reason why you wouldn't just use the standard library methods on |
yes, libm is used in the uom crate for no_std builds. In the uom tests quickcheck is used which is generic over f32/f64 thus we need also generic libm methods. |
|
||
use crate::*; | ||
|
||
pub struct Libm<T>(PhantomData<T>); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add some doc comments here to explain what this type is and some examples of how it can be used.
src/libm_helper.rs
Outdated
} | ||
)* | ||
} | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you fix the formatting here? Use spaces instead of tabs, and remove the blank lines.
src/libm_helper.rs
Outdated
pub struct Libm<T>(PhantomData<T>); | ||
|
||
macro_rules! libm_helper { | ||
($t:ident, $(($libm_fn:ident => $func:ident($($arg:ident: $arg_type:ty),*) -> ($($ret_type:ty),*)));*) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you spread this out over multiple lines to make it easier to read?
Add editorconfig + docs refactor
trim_trailing_whitespace = false | ||
|
||
[*.yml] | ||
indent_size = 2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't commit your editorconfig.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because you mentioned it earlier, it would be nice to configure and document the suggested format in the project.
I copied the .editorconfig from the rust project.
This PR adds a generic
Libm<T>
helper to abstract over f32 and f64.With this you can call the libm functions like this
libm::Libm::<f32>::acos(x)
andlibm::Libm::<f64>::acos(x)
.I think it should all be zero-cost abstraction.