math package - conversion functions between rad and grad

2,208 views
Skip to first unread message

Johann Höchtl

unread,
Feb 4, 2011, 6:11:39 PM2/4/11
to golang-nuts
The trigonometric functions of the math package operate on rads, the
mathematically sane way.

Most people operate in degrees. Conversion between these two systems
is trivial, but wouldn't it be a good fit if the math package contains

RadtoGrad(rad float64) float64

and

GradtoRad(grad float64) float64

-- Johann

Rob 'Commander' Pike

unread,
Feb 4, 2011, 6:25:46 PM2/4/11
to Johann Höchtl, golang-nuts

Surely you mean RadToDeg? No one I know has ever used a grad to measure an angle (puns aside).

-rob

Michael Jones

unread,
Feb 4, 2011, 6:36:36 PM2/4/11
to Rob 'Commander' Pike, Johann Höchtl, golang-nuts
The construction industries use grads (gradients) which are 400 to a
circle, so a "3 percent slope" can be 3 grads, this is why the
angle-mode annunciator and button on HP calculators has 'DRG'

--
Michael T. Jones, Chief Technology Advocate, Google Inc.
1600 Amphitheatre Parkway, Mountain View, California 94043
Email: m...@google.com Mobile: 408-507-8160 Fax: 650-649-1938
Advancing the technology to organize the world's information and
make it universally accessible and useful

Mehmet D. Akın

unread,
Feb 4, 2011, 7:34:04 PM2/4/11
to Michael Jones, Rob 'Commander' Pike, Johann Höchtl, golang-nuts
Survey engineers, cartographers uses grad as well.

Johann Höchtl

unread,
Feb 5, 2011, 3:57:28 AM2/5/11
to golang-nuts
Yes of course; A mistake trigered by the peculiarities of the german
language ;)

1 degree = 1/360 of a circle
1 grad = 1/400 of circle

But as noted, 'grads' may also have a point.

> -rob

Michael Jones

unread,
Feb 5, 2011, 5:25:03 PM2/5/11
to Johann Höchtl, golang-nuts
Do you propose functions, or are handy multiplicative constants good enough?

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]
)
--

Michael T. Jones

   Chief Technology Advocate, Google Inc.

   1600 Amphitheatre Parkway, Mountain View, California 94043

   Email: m...@google.com  Mobile: 650-335-5765  Fax: 650-649-1938

   Organizing the world's information to make it universally accessible and useful


Rob 'Commander' Pike

unread,
Feb 5, 2011, 7:57:43 PM2/5/11
to Michael Jones, Johann Höchtl, golang-nuts
If necessary, I would advocate constants, easily and accurately
computed at compile time, as in:

const (
RadToDeg = 180/Pi
DegToRad = Pi/180
RadToGrad = 200/Pi
GradToDeg = Pi/200
)

-rob

Johann Höchtl

unread,
Feb 6, 2011, 1:57:31 AM2/6/11
to golang-nuts
The overhead of a function call (in the absence of compile time
optimisation) make a constant solution certainly more appealing.

> -rob
Reply all
Reply to author
Forward
0 new messages