From f9a659f7abbc374f04cf40e37d073bb4b508473e Mon Sep 17 00:00:00 2001 From: matkuki Date: Fri, 17 Jun 2016 21:52:41 +0200 Subject: [PATCH] Windows MSVC < 2012 'round' function update Microsoft Visual C++ compilers prior to 2012 do not implement the 'round', 'roundl' or 'roundf' functions. This change is fixes this. Tested it with MSVC 2010. --- lib/pure/math.nim | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/pure/math.nim b/lib/pure/math.nim index 2b903bedbf..f31ad5db4f 100644 --- a/lib/pure/math.nim +++ b/lib/pure/math.nim @@ -138,11 +138,6 @@ when not defined(JS): proc exp*(x: float64): float64 {.importc: "exp", header: "".} ## Computes the exponential function of `x` (pow(E, x)) - proc round0(x: float32): float32 {.importc: "roundf", header: "".} - proc round0(x: float64): float64 {.importc: "round", header: "".} - ## Converts a float to an int by rounding. Used internally by the round - ## function when the specified number of places is 0. - proc arccos*(x: float32): float32 {.importc: "acosf", header: "".} proc arccos*(x: float64): float64 {.importc: "acos", header: "".} ## Computes the arc cosine of `x` @@ -224,6 +219,17 @@ when not defined(JS): ## ## .. code-block:: nim ## echo ceil(-2.1) ## -2.0 + + when defined(windows): + proc round0[T: float32|float64](x: T): T = + ## Windows compilers prior to MSVC 2012 do not implement 'round', + ## 'roundl' or 'roundf'. + result = if x < 0.0: ceil(x - T(0.5)) else: floor(x + T(0.5)) + else: + proc round0(x: float32): float32 {.importc: "roundf", header: "".} + proc round0(x: float64): float64 {.importc: "round", header: "".} + ## Converts a float to an int by rounding. Used internally by the round + ## function when the specified number of places is 0. proc fmod*(x, y: float32): float32 {.importc: "fmodf", header: "".} proc fmod*(x, y: float64): float64 {.importc: "fmod", header: "".}