Skip to content

Move F in DualNum from parameter to associated type - #115

Merged
prehner merged 2 commits into
masterfrom
primitive_type
Aug 12, 2026
Merged

prehner merged 2 commits into
masterfrom
primitive_type

Conversation

@prehner

@prehner prehner commented Aug 8, 2026 •

Copy link
Copy Markdown
Contributor

Thanks to @dwuertz for the suggestion!

The underlying primitive (mostly f32 or f64) should be an associated type of DualNum rather than a type parameter, because there is only one reasonable choice per implementation. It wasn't because of some troubles with orphan rule and the implementation of arithmetic operations with floats. However, with the right trait bounds, the compiler can apparently be satisfied. This also completely removes the PhantomData<F> fields from all dual number types.

In places that are hardcoded to a specific float precision (e.g., FeOs) this basically means that every occurrence of DualNum<f64> needs to be replaced with DualNum<Primitive = f64> which is somewhat cumbersome but overall not a limitation.

@prehner prehner linked an issue Aug 8, 2026 that may be closed by this pull request
@prehner
prehner force-pushed the primitive_type branch 2 times, most recently from c455186 to 16710ef Compare August 8, 2026 14:52
@dwuertz

dwuertz commented Aug 9, 2026

Copy link
Copy Markdown

Awesome, thanks so much for addressing this so quickly! The new API is working well here.

@prehner
prehner force-pushed the primitive_type branch 2 times, most recently from cc9ae68 to c819b5d Compare August 11, 2026 13:23
@prehner

prehner commented Aug 11, 2026

Copy link
Copy Markdown
Contributor Author

@g-bauer what do you think?

@g-bauer

g-bauer commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Looks good to me.

@prehner
prehner merged commit ce0e152 into master Aug 12, 2026
10 checks passed
@prehner
prehner deleted the primitive_type branch August 12, 2026 11:17
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.

Underlying type of DualNum should be an associated type

3 participants