Merge pull request #2977 from apense/patch-5
Conversion between radians and degrees.Fixes #2881
This commit is contained in:
commit
43c64c7545
1 changed files with 13 additions and 0 deletions
|
|
@ -12,6 +12,10 @@
|
||||||
## Basic math routines for Nim.
|
## Basic math routines for Nim.
|
||||||
## This module is available for the `JavaScript target
|
## This module is available for the `JavaScript target
|
||||||
## <backends.html#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"
|
include "system/inclrtl"
|
||||||
{.push debugger:off .} # the user does not want to trace a part
|
{.push debugger:off .} # the user does not want to trace a part
|
||||||
|
|
@ -38,6 +42,7 @@ const
|
||||||
## meaningful digits
|
## meaningful digits
|
||||||
## after the decimal point
|
## after the decimal point
|
||||||
## for Nim's ``float`` type.
|
## for Nim's ``float`` type.
|
||||||
|
RadPerDeg = PI / 180.0 ## number of radians per degree
|
||||||
|
|
||||||
type
|
type
|
||||||
FloatClass* = enum ## describes the class a floating point value belongs to.
|
FloatClass* = enum ## describes the class a floating point value belongs to.
|
||||||
|
|
@ -317,6 +322,14 @@ else:
|
||||||
|
|
||||||
{.pop.}
|
{.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 =
|
proc `mod`*(x, y: float): float =
|
||||||
## Computes the modulo operation for float operators. Equivalent
|
## Computes the modulo operation for float operators. Equivalent
|
||||||
## to ``x - y * floor(x/y)``. Note that the remainder will always
|
## to ``x - y * floor(x/y)``. Note that the remainder will always
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue