Commit a38c8985 authored by Mart Lubbers's avatar Mart Lubbers

implement ^ and isEven for integers and use it in windows System.Time

parent d971c0ae
Pipeline #31521 passed with stage
in 3 minutes and 6 seconds
......@@ -21,11 +21,13 @@ instance sign Integer
instance / Integer
instance rem Integer
//instance ^ Integer
instance ^ Integer
instance == Integer
instance < Integer
instance isEven Integer
class toInteger a :: !a -> Integer
instance toChar Integer
......
......@@ -40,6 +40,24 @@ instance * Integer
where
(*) a b = mul_integer a b
instance ^ Integer
where
(^) x n
| n < zero = abort "^ (Integer) called with negative power argument"
= pow x n
where
pow a b
| b == zero = one
# x = pow a (b / toInteger 2)
| isEven b = x * x
= a * x * x
instance isEven Integer
where
isEven {integer_s=s,integer_a=a}
| size a == 0 = isEven s
= isEven a.[0]
instance zero Integer
where
zero = {integer_s = 0, integer_a = {}}
......
......@@ -175,7 +175,6 @@ TICKSDIFF64 =: 11644473600 * TICKSPERSEC64
//Number of ticks per second (100 ns ticks)
TICKSPERSEC32 =: toInteger 10000000
TICKSPERSEC64 =: 10000000
/*
* On windows GetSystemTimeAsFileTime returns a struct containing 2 32bit unsigned integers.
* On 64 bit we therefore use an array of length 1, on 32 bit of length two.
......@@ -189,7 +188,7 @@ where
= ({tv_sec=(is.[0] - TICKSDIFF64) / TICKSPERSEC64, tv_nsec=(is.[0] rem TICKSPERSEC64) * 100}, w)
nsTime32 w
# (is, w) = GetSystemTimeAsFileTime {0,0} w
# ticks = uintToInt is.[0] + foldr ($) (uintToInt is.[1]) (repeatn 32 ((*) (toInteger 2))) - TICKSDIFF32
# ticks = uintToInt is.[0] + uintToInt is.[1] ^ toInteger 32 - TICKSDIFF32
= ({tv_sec=toInt (ticks / TICKSPERSEC32), tv_nsec=toInt (ticks rem TICKSPERSEC32) * 100}, w)
uintToInt :: Int -> Integer
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment