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

proposal: math: add deg <-> rad conversion constants #19587

Closed
niondir opened this issue Mar 17, 2017 · 7 comments
Closed

proposal: math: add deg <-> rad conversion constants #19587

niondir opened this issue Mar 17, 2017 · 7 comments

Comments

@niondir
Copy link

niondir commented Mar 17, 2017

I was doing some image processing and with rotation I noticed that all the trigonometric functions are operating on rads. But people can better think in deg e.g. "I want to turn my picture by 90°" and not by 1,5708 rads.

I would like to add some constants to the math package:

// Trigonometric constants.
const (
	DegToRad = 0.017453292519943295769236907684886127134428718885417 // N[Pi/180, 50]
	RadToDeg = 57.295779513082320876798154814105170332405472466564   // N[180/Pi, 50]

	GradToRad = 0.015707963267948966192313216916397514420985846996876 // N[Pi/200, 50]
	RadToGrad = 63.661977236758134307553505349005744813783858296183   // N[200/Pi, 50]
)

What version of Go are you using (go version)?

1.8

What operating system and processor architecture are you using (go env)?

windows amd64

@ALTree ALTree changed the title Trigonometric constants to math package proposal: math: add deg <-> rad conversion constants Mar 17, 2017
@ALTree ALTree added this to the Proposal milestone Mar 17, 2017
@cznic
Copy link
Contributor

cznic commented Mar 17, 2017

Instead of documenting it in the comments N[Pi/180, 50], the constants can be defined within math as

const (
        DegToRad = Pi/180
        ...
)

directly with no loss of precision. But the same can be done in client's code (math.Pi/180 etc.) and IMO constants in math should be restricted to the few fundamental ones only (as it mostly is now).

@mvdan
Copy link
Member

mvdan commented Mar 17, 2017

Agree with @cznic - if getting these constants is so trivial, why should they be included in math? Pi/180 is even shorter than DegToRad.

@niondir
Copy link
Author

niondir commented Mar 17, 2017

One thing I like about go is that many thinks are just easy to do without a lot of thinking.

It the same as with constants like time.Minute = 60 * Second. Well everyone knows that a minute has 60 seconds and could declare the constant him self. But it's in the std lib of go and I like it a lot.
It's just that the time lib is build up on Nanosecond and offers conversions from "human readable" values like Minutes. Same with Rad and Deg, it's good to have all implementations build up on Rad for good reasons, but as a user I don't want to bother with it and want to be able to convert this values.

@mvdan
Copy link
Member

mvdan commented Mar 17, 2017

@niondir I think the policy regarding what convenience constants to include in std is directly influenced by how often they would be used. time.Minute is very common. I would assume math.DegToRad wouldn't be.

Perhaps this warrants some investigation, for example to see how often Pi / 180 or 0.01745329... appear in the wild.

@griesemer
Copy link
Contributor

I'm against this. Even if I have a constant math.DegToRad it's not necessarily obvious how to use it (do I multiply with it, divide it?). Everybody doing trigonometric operations that require conversions will know that 2*pi corresponds to 360 degrees or 400 gradians. It's trivial to write those conversions. And it's trivial to locally introduce constants if necessary. It's different for the time constants which are used more frequently, and for which it's very clear what they mean.

@robpike
Copy link
Contributor

robpike commented Mar 17, 2017

@griesemer captured my own thinking well.

@bradfitz
Copy link
Contributor

Sounds like there's not support for this. Marking declined.

@golang golang locked and limited conversation to collaborators Mar 17, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

8 participants