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

make measurements work with at-printf #102

Merged
merged 2 commits into from
Apr 9, 2021

Conversation

ranocha
Copy link
Contributor

@ranocha ranocha commented Apr 8, 2021

I implemented specializations of Printf.tofloat to allow printing (the value of) Measurements. This is useful when working with functions that print some information during the computation, cf. https://discourse.julialang.org/t/forwarddiff-jl-and-printf/57694. This approach is also used in ForwardDiff.jl, cf. JuliaDiff/ForwardDiff.jl#511.

The basic reasoning for this is that Measurement's identify as AbstractFloats, which are Reals. Hence, they can (and will) be used in quite general contexts where real numbers can appear. If someone implements a numerical algorithm in generic Julia code that can take quite some time and does not need to make use of Measurements.jl directly, they might have some intermediate printing statements to inform the user about the progress. Hence, it would be really nice if Measurements could still be used within such generic code written for Real numbers.

Closes #101

Copy link
Member

@giordano giordano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Only a minor comment about where to put using Printf.

@@ -24,6 +24,8 @@ module Measurements
# Calculus is used to calculate numerical derivatives in "@uncertain" macro.
using Calculus

import Printf
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd move this to src/show.jl

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. Done in 8af7314

@giordano giordano merged commit 500ff82 into JuliaPhysics:master Apr 9, 2021
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.

making measurements work with Printf
2 participants