Tehforsch / diman

Define rust compile time unit systems using const generics
52 stars 2 forks source link

Compile time errors for `sqrt` and `cbrt` on quantities with dimensions that are not divisible by 2/3 #42

Closed Tehforsch closed 8 months ago

Tehforsch commented 8 months ago

Currently, the code panics during runtime, which is not ideal. I don't think there is a way to constrain the impl of sqrt/cbrt to only the divisible dimensions, so I don't know if this is solvable currently.

I briefly considered monomorphizing the impls by hand (i.e. writing out impls for all the divisible dimensions up to some maximum exponents in each of the base dimensions), but that just seems awful and the exponential increase in generated functions (which will have to be generated no matter what, as opposed to the monomorphization the compiler will do) is certainly not good for compilation speed.

jedbrown commented 8 months ago

This would be moot if rational dimensions #25 were supported by default. Implementation aside, I don't know enough about their use to say whether they should be allowed by default.

Tehforsch commented 8 months ago

I just realized that I was wrong - we do get a (very ugly) compile-time error, since its a runtime panic in a const fn. In any case, I am about to add support for #25 in #48, so we should have a more reasonable solution to this problem in the future.