Skip to content
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

Merged
merged 1 commit into from Feb 11, 2023

Conversation

moritz-meier
Copy link
Contributor

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) and libm::Libm::<f64>::acos(x).
I think it should all be zero-cost abstraction.

@Amanieu
Copy link
Member

Amanieu commented Jan 11, 2023

Are you using this on an embedded target? Otherwise I see no reason why you wouldn't just use the standard library methods on f32 and f64 directly.

@moritz-meier
Copy link
Contributor Author

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.

iliekturtles/uom#309


use crate::*;

pub struct Libm<T>(PhantomData<T>);
Copy link
Member

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.

}
)*
}
};
Copy link
Member

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.

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),*)));*) => {
Copy link
Member

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
Copy link
Member

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.

Copy link
Contributor Author

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.

@Amanieu Amanieu merged commit cacbf24 into rust-lang:master Feb 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants