summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2012-07-25 00:56:34 +0200
committerAraq <rumpf_a@web.de>2012-07-25 00:56:34 +0200
commit39f399f42442af8b3286ae3ff679d74762b60c35 (patch)
treeb707a9353905f51dd62af9228914ccdef5932c4c
parentb5a44481f9657341904e65729de8dddc22cd8330 (diff)
downloadNim-39f399f42442af8b3286ae3ff679d74762b60c35.tar.gz
fixes #172
-rwxr-xr-xcompiler/ccgexprs.nim2
-rwxr-xr-xlib/nimbase.h12
2 files changed, 7 insertions, 7 deletions
diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim
index 42f19b069..6c8510ff8 100755
--- a/compiler/ccgexprs.nim
+++ b/compiler/ccgexprs.nim
@@ -524,7 +524,7 @@ proc unaryArith(p: BProc, e: PNode, d: var TLoc, op: TMagic) =
       "(($3)(NU32)(NU64)($1))", # ToU32
       "((double) ($1))",      # ToFloat
       "((double) ($1))",      # ToBiggestFloat
-      "float64ToInt32($1)",   # ToInt XXX: this is not correct!
+      "float64ToInt32($1)",   # ToInt
       "float64ToInt64($1)"]   # ToBiggestInt
   var
     a: TLoc
diff --git a/lib/nimbase.h b/lib/nimbase.h
index a73933a40..71f3b0d7c 100755
--- a/lib/nimbase.h
+++ b/lib/nimbase.h
@@ -352,14 +352,14 @@ typedef char* NCSTRING;
 #  define NIM_IMAN 0
 #endif
 
-static N_INLINE(NI32, float64ToInt32)(double val) {
-  val = val + 68719476736.0*1.5;
-  /* 2^36 * 1.5,  (52-_shiftamt=36) uses limited precisicion to floor */
-  return ((NI32*)&val)[NIM_IMAN] >> 16; /* 16.16 fixed point representation */
+static N_INLINE(NI, float64ToInt32)(double x) {
+  /* nowadays no hack necessary anymore */
+  return x >= 0 ? (NI)(x+0.5) : (NI)(x-0.5);
 }
 
-static N_INLINE(NI32, float32ToInt32)(float val) {
-  return float64ToInt32((double)val);
+static N_INLINE(NI32, float32ToInt32)(float x) {
+  /* nowadays no hack necessary anymore */
+  return x >= 0 ? (NI32)(x+0.5) : (NI32)(x-0.5);
 }
 
 #define float64ToInt64(x) ((NI64) (x))