-
Notifications
You must be signed in to change notification settings - Fork 113
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
dispatch on units of angle #38
Comments
Wow, small world, someone else at Caltech found my package... First, let me argue that no small angle approximation is required. Consider that the circumference of a circle is To do the dispatch you want, I offer two solutions:
Regarding |
Hi! Julia users at Caltech are a rare breed right now.
For some reason I was only thinking about chords (and not arcs) when I made this statement. You are definitely correct here. Between options 1 and 2 my preference is for option 2 because it is stylistically more Julian (although I agree that the 2 options are functionally equivalent because the compiler will delete the dead branch if you call it with the right types). However there is nothing stopping me from putting the I was never asking about performance (I actually don't mind a runtime check) but rather being able to conveniently define functions that act on angles. For example: julia> using Unitful
julia> type Vec3
x::Float64
y::Float64
z::Float64
end
julia> Vec3(::Unitful.Length, ::Unitful.Length, ::Unitful.Length) = ... cartesian constructor ...
julia> Vec3(::Unitful.Length, ::Angle, ::Angle) = ... spherical constructor ... In this example, my motivation is a convenient interface for the user to pick between the cartesian and spherical constructors. Without attaching units to the arguments I can't discern the user's intention from the types of the arguments. I would instead have to define two functions For this reason the Lastly I believe julia> sind(360)
0.0
julia> sin(deg2rad(360))
-2.4492935982947064e-16 Also thanks for developing this package! I've always felt like SIUnits needed some TLC, so it's great to see Unitful with some great ideas. |
You're welcome! And thank you for alerting me to the purpose of Unless I misunderstand what you want, the correct method or constructor should be called even if you leave off the
I guess I am hesitant to include an Angle definition, at least for the time being. I see the convenience, but since we agree angles have no dimensions, I'd need to come up with a fair restriction on the numeric types an angle is allowed to be, which is hard to decide in general when you interact with other packages. The typealias I provided could prevent you from playing nicely with other package-defined |
I know this is a very old thread, but just in case someone else finds it: checkout DimensionfulAngles.jl. It treats angles as a dimension which allows for dispatching. |
I am interested in adding Unitful as a dependency for a package I maintain, but it is important that I am able to dispatch on units of angle. For example I have a 3-vector type, and it would be nice to provide constructors like (without units all of the arguments are
Float64
and you don't get the convenience of having both constructors):I am also going to argue that "Angle" should be a fundamental (not derived dimension). The idea that angles are "dimensionless" seems to originate from the idea that it is a
length / length
(see table 3 http://physics.nist.gov/cuu/Units/units.html), but this is only correct in the small angle approximation. In general you need to use a trig function to get from an angle to something that is truly dimensionless. Or rather you need an inverse trig function to get an angle from something that is dimensionless.Finally it would also be really cool if
sin(1°)
dispatched tosind(1)
.(see https://github.com/Keno/SIUnits.jl/blob/d25c43483828c954cd63c19cbe3ff209a614bbd1/src/nonsiunits.jl#L15-L22)
The text was updated successfully, but these errors were encountered: