-
Notifications
You must be signed in to change notification settings - Fork 8
Add f32 calculations #21
Comments
Any thoughts on names for f32 calculations? |
I was thinking on using the same names as the f64 version but with vsop87::earth_moon_f32(jde:f32) -> (f32, f32, f32, f32, f32, f32) for pub fn earth_moon(jde: f64) -> (f64, f64, f64, f64, f64, f64) What I'm not sure about is if we would need to add a new set of constants, or doing a lossy Also, we would need to create new tests for this version. We would also need to add the main functions src/lib.rs#L39 In any case, there is another option, which would probably be even better for the future #19. We could create a feature named #[cfg(feature = "f64")]
pub fn mercury(jde: f64) -> (f64, f64, f64, f64, f64, f64) {
. . .
}
#[cfg(feature = "f32")]
pub fn mercury(jde: f32) -> (f32, f32, f32, f32, f32, f32) {
. . .
} This would also enable compile time optimizations in constants, by having two versions of the planet modules ( #[cfg(feature = "f32")]
mod mercury_f32;
#[cfg(feature = "f64")]
mod mercury_f64; Both files would be an exact copy, just changing the header for each constant ( I want to read your opinion though :) |
I did this as a quick thing to to which you like better, this is the features https://github.com/tonetheman/vsop87-rs/tree/f32_experiment It is just a branch with the features added to Cargo.toml and one new (copied and changed) function in lib_32.rs I did a build with this I am new enough to rust to not exactly know how to even tell it is doing anything (ha). The tests still passed which made me think Any thoughts? |
You would need to include the feature in the [features]
default=["f64"]
f32= []
f64 = [] |
alright i will look into that and see where i get! |
Ok look at my branch now. Features (at least the default part) do not work like I had thought. The default feature appears to always be used. So when I have an f32 func and a f64 func defined with the same name when you do this command you will see both features on at once cargo build --features f32 --verbose I read you can set features as cherry picked but it looks like it is in the toml file? |
Yes, if you don't want to compile default features, you need to specify
|
alright thanks I got enough to go ahead then that was what I needed! |
Is this feature still planned? An approach like iliekturtles/uom implemented for multiple types could be used. |
To prevent a large amount of code duplications generics could be used. I made some tests in https://github.com/NiklasVousten/vsop87-rs/tree/f32 Currently only Mercury is capable of f32 operations, and the tests need to be modified to allow for smaller precision. The constant arrays are currently converted. But with a duplication of those, this step could be skipped and thus have additional constant f32 arrays. Convertion would be less work though. Any thoughts? |
Currently all calculations are done in
f64
types, but many users could benefit from less precise f32 calculations, mainly in platforms with smaller word sizes.The text was updated successfully, but these errors were encountered: