diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2015-06-25 13:14:59 +0200 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2015-06-25 13:14:59 +0200 |
commit | 43c64c7545e155768e117c1894bf1a78af0bf5a8 (patch) | |
tree | 0727d7620ffdfba289a3b7a287ec556db449eb28 | |
parent | 6de5c1e86da46c9a1a5daaa7f5bbdccaf4b78542 (diff) | |
parent | bfcbe64778f5bd9580aac9a2ae8c735257a2bade (diff) | |
download | Nim-43c64c7545e155768e117c1894bf1a78af0bf5a8.tar.gz |
Merge pull request #2977 from apense/patch-5
Conversion between radians and degrees.Fixes #2881
-rw-r--r-- | lib/pure/math.nim | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/pure/math.nim b/lib/pure/math.nim index 7a88694b5..c345d9d51 100644 --- a/lib/pure/math.nim +++ b/lib/pure/math.nim @@ -12,6 +12,10 @@ ## Basic math routines for Nim. ## This module is available for the `JavaScript target ## <backends.html#the-javascript-target>`_. +## +## Note that the trigonometric functions naturally operate on radians. +## The helper functions `degToRad` and `radToDeg` provide conversion +## between radians and degrees. include "system/inclrtl" {.push debugger:off .} # the user does not want to trace a part @@ -38,6 +42,7 @@ const ## meaningful digits ## after the decimal point ## for Nim's ``float`` type. + RadPerDeg = PI / 180.0 ## number of radians per degree type FloatClass* = enum ## describes the class a floating point value belongs to. @@ -317,6 +322,14 @@ else: {.pop.} +proc degToRad*[T: float32|float64](d: T): T {.inline.} = + ## Convert from degrees to radians + result = T(d) * RadPerDeg + +proc radToDeg*[T: float32|float64](d: T): T {.inline.} = + ## Convert from radians to degrees + result = T(d) / RadPerDeg + proc `mod`*(x, y: float): float = ## Computes the modulo operation for float operators. Equivalent ## to ``x - y * floor(x/y)``. Note that the remainder will always |