SymbolicML / DynamicQuantities.jl

Efficient and type-stable physical quantities in Julia
https://symbolicml.org/DynamicQuantities.jl/dev/
Apache License 2.0
132 stars 17 forks source link

Use `Int64 / C` as default #20

Closed MilesCranmer closed 1 year ago

MilesCranmer commented 1 year ago

cc @oscardssmith

I think it would probably be much faster to use Int64 / C, for some choice of constant C, than to use Rational{Int16} as is currently done – as it would avoid repeated gcd calls.

We would want to pick some constant C such that most rationals expressed by Rational{Int16} that people would typically want to use could also be expressed this way.

MilesCranmer commented 1 year ago

What about, for example,

C = 2^8 * 3^6 * 5^4 * 7^2 * 11^2 * 13 * 15  # = 2385171360000

meaning you could represent any fraction which can be built by a combination of those powers. But you could not represent, say, 1/(15^2). But you could get awfully close.

The typemax of this would be 188232082384791343//2752120800000, which evaluates to ~68395 - again, likely more than anybody would need.

oscardssmith commented 1 year ago

I really think the default should probably be Int8/6. There are some cases where you need finer granularity than that, but they're pretty rare and I don't think they should be the default.

MilesCranmer commented 1 year ago

(Fixed by #21 but forgot to close this)