summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2012-06-28 08:33:25 +0200
committerAraq <rumpf_a@web.de>2012-06-28 08:33:25 +0200
commit2900ceae3580a9f1e83b500cf1abcdfe77762cad (patch)
tree1279b1199dcd7f1af2949355e692b1857960a0ee /lib
parentb5d34242ca7156ec702f8e63a01c9cd059d28e5f (diff)
downloadNim-2900ceae3580a9f1e83b500cf1abcdfe77762cad.tar.gz
changed integer promotion rules; added math.fmod
Diffstat (limited to 'lib')
-rwxr-xr-xlib/posix/posix.nim2
-rwxr-xr-xlib/pure/math.nim11
-rwxr-xr-xlib/system/alloc.nim4
-rwxr-xr-xlib/system/ansi_c.nim4
-rwxr-xr-xlib/system/sysio.nim4
5 files changed, 15 insertions, 10 deletions
diff --git a/lib/posix/posix.nim b/lib/posix/posix.nim
index ca29f5fcc..ff121777e 100755
--- a/lib/posix/posix.nim
+++ b/lib/posix/posix.nim
@@ -188,7 +188,7 @@ type
   Tid* {.importc: "id_t", header: "<sys/types.h>".} = int
   Tino* {.importc: "ino_t", header: "<sys/types.h>".} = int
   TKey* {.importc: "key_t", header: "<sys/types.h>".} = int
-  TMode* {.importc: "mode_t", header: "<sys/types.h>".} = int
+  TMode* {.importc: "mode_t", header: "<sys/types.h>".} = cint
   TNlink* {.importc: "nlink_t", header: "<sys/types.h>".} = int
   TOff* {.importc: "off_t", header: "<sys/types.h>".} = int64
   TPid* {.importc: "pid_t", header: "<sys/types.h>".} = int
diff --git a/lib/pure/math.nim b/lib/pure/math.nim
index 6f3135d13..587671165 100755
--- a/lib/pure/math.nim
+++ b/lib/pure/math.nim
@@ -188,6 +188,8 @@ when not defined(ECMAScript):
   proc floor*(x: float): float {.importc: "floor", nodecl.}
   proc ceil*(x: float): float {.importc: "ceil", nodecl.}
 
+  proc fmod*(x, y: float): float {.importc: "fmod", header: "<math.h>".}
+
 else:  
   proc mathrandom(): float {.importc: "Math.random", nodecl.}
   proc floor*(x: float): float {.importc: "Math.floor", nodecl.}
@@ -230,10 +232,13 @@ else:
     var y = exp(2.0*x)
     return (y-1.0)/(y+1.0)
 
+proc `mod`*(x, y: float): float =
+  result = if y == 0.0: x else: x - y * (x/y).floor
+
 type
-  TRunningStat* = object  ## an accumulator for statistical data
-    n*: int               ## number of pushed data
-    sum*, min*, max*, mean*: float ## self-explaining
+  TRunningStat* {.pure,final.} = object  ## an accumulator for statistical data
+    n*: int                              ## number of pushed data
+    sum*, min*, max*, mean*: float       ## self-explaining
     oldM, oldS, newS: float
 
 proc push*(s: var TRunningStat, x: float) = 
diff --git a/lib/system/alloc.nim b/lib/system/alloc.nim
index 981dac977..ba172373d 100755
--- a/lib/system/alloc.nim
+++ b/lib/system/alloc.nim
@@ -23,7 +23,7 @@ when defined(posix):
   const
     PROT_READ  = 1             # page can be read 
     PROT_WRITE = 2             # page can be written 
-    MAP_PRIVATE = 2            # Changes are private 
+    MAP_PRIVATE = 2'i32        # Changes are private 
   
   when defined(macosx) or defined(bsd):
     const MAP_ANONYMOUS = 0x1000
@@ -40,7 +40,7 @@ when defined(posix):
   
   proc osAllocPages(size: int): pointer {.inline.} = 
     result = mmap(nil, size, PROT_READ or PROT_WRITE, 
-                           MAP_PRIVATE or MAP_ANONYMOUS, -1, 0)
+                             MAP_PRIVATE or MAP_ANONYMOUS, -1, 0)
     if result == nil or result == cast[pointer](-1):
       raiseOutOfMem()
       
diff --git a/lib/system/ansi_c.nim b/lib/system/ansi_c.nim
index e328f7099..3376b9413 100755
--- a/lib/system/ansi_c.nim
+++ b/lib/system/ansi_c.nim
@@ -14,9 +14,9 @@
 {.push hints:off}
 
 proc c_strcmp(a, b: CString): cint {.nodecl, noSideEffect, importc: "strcmp".}
-proc c_memcmp(a, b: CString, size: cint): cint {.
+proc c_memcmp(a, b: CString, size: int): cint {.
   nodecl, noSideEffect, importc: "memcmp".}
-proc c_memcpy(a, b: CString, size: cint) {.nodecl, importc: "memcpy".}
+proc c_memcpy(a, b: CString, size: int) {.nodecl, importc: "memcpy".}
 proc c_strlen(a: CString): int {.nodecl, noSideEffect, importc: "strlen".}
 proc c_memset(p: pointer, value: cint, size: int) {.nodecl, importc: "memset".}
 
diff --git a/lib/system/sysio.nim b/lib/system/sysio.nim
index adcb32b42..15f87896a 100755
--- a/lib/system/sysio.nim
+++ b/lib/system/sysio.nim
@@ -199,8 +199,8 @@ proc Open(f: var TFile, filename: string,
   var p: pointer = fopen(filename, FormatOpen[mode])
   result = (p != nil)
   f = cast[TFile](p)
-  if bufSize > 0:
-    if setvbuf(f, nil, IOFBF, bufSize) != 0'i32:
+  if bufSize > 0 and bufSize <= high(cint):
+    if setvbuf(f, nil, IOFBF, bufSize.cint) != 0'i32:
       raise newException(EOutOfMemory, "out of memory")
   elif bufSize == 0:
     discard setvbuf(f, nil, IONBF, 0)