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

Use fallback implementation for min, max #675

Merged
merged 2 commits into from
Aug 12, 2023

Conversation

Socob
Copy link
Contributor

@Socob Socob commented Aug 9, 2023

min and max are currently explicitly defined for AbstractQuantity arguments and have their own separate re-implementation of uconvert for some reason. However, it turns out that this is unnecessary since the standard fallback implementations of min and max already work perfectly fine for AbstractQuantity, because comparison is also defined. Thus, this simply removes these extra method definitions, which, as a bonus, also provides all of the error checking added in #648 to min and max as well.

Fixes missing floating point overflow/underflow checks (cf. #647).
@sostock
Copy link
Collaborator

sostock commented Aug 9, 2023

Great! This also fixes another bug, because the deleted methods used < instead of isless:

Before (wrong):

julia> min(NaN*u"m", 1.0u"m")
1.0 m

julia> min(1.0u"m", NaN*u"m")
NaN m

After (correct):

julia> min(NaN*u"m", 1.0u"m")
1.0 m

julia> min(1.0u"m", NaN*u"m")
1.0 m

It would be good to add tests for that as well.

@Socob
Copy link
Contributor Author

Socob commented Aug 11, 2023

@sostock Ah yes, I didn’t even notice that. Tests added!

@sostock sostock merged commit 7efb4b6 into PainterQubits:master Aug 12, 2023
13 checks passed
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.

2 participants