From 66a7e3d37c0303997a6b1a3b7ec263dfb8c07748 Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Tue, 15 Sep 2009 23:22:22 +0200 Subject: added tools and web dirs --- lib/pure/math.nim | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) mode change 100644 => 100755 lib/pure/math.nim (limited to 'lib/pure/math.nim') diff --git a/lib/pure/math.nim b/lib/pure/math.nim old mode 100644 new mode 100755 index a3e57e403..bca45894c --- a/lib/pure/math.nim +++ b/lib/pure/math.nim @@ -1,7 +1,7 @@ # # # Nimrod's Runtime Library -# (c) Copyright 2008 Andreas Rumpf +# (c) Copyright 2009 Andreas Rumpf # # See the file "copying.txt", included in this # distribution, for details about the copyright. @@ -83,10 +83,12 @@ proc nextPowerOfTwo*(x: int): int = result = result or (result shr 1) Inc(result) -proc countBits*(n: int32): int {.noSideEffect.} +proc countBits32*(n: int32): int {.noSideEffect.} = ## counts the set bits in `n`. - -include "system/cntbits" + var v = n + v = v -% ((v shr 1'i32) and 0x55555555'i32) + v = (v and 0x33333333'i32) +% ((v shr 2'i32) and 0x33333333'i32) + result = ((v +% (v shr 4'i32) and 0xF0F0F0F'i32) *% 0x1010101'i32) shr 24'i32 proc sum*[T](x: openarray[T]): T {.noSideEffect.} = ## computes the sum of the elements in `x`. -- cgit 1.4.1-2-gfad0