Merge pull request #2977 from apense/patch-5

Conversion between radians and degrees.Fixes #2881
This commit is contained in:
Andreas Rumpf
2015-06-25 13:14:59 +02:00

View File

@@ -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