Commit 8aae8fa9 authored by Mart Lubbers's avatar Mart Lubbers

Merge branch '80-follow-up-from-fix-nstime-on-64-bit-windows-machines' into 'master'

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

Closes #80

See merge request !288
parents d08d8618 d0a38784
Pipeline #31819 failed with stage
in 2 minutes and 15 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,48 @@ instance * Integer
where
(*) a b = mul_integer a b
instance ^ Integer
where
(^) :: !Integer !Integer -> Integer
(^) x n
| size n.integer_a==0
| n.integer_s<=0
| n.integer_s==0
= one
= negative_power_error
= pow x n.integer_s
| n.integer_s<0
= negative_power_error
| size x.integer_a<>0 || x.integer_s < -1 || x.integer_s > 1
= abort "^ (Integer) overflow"
| x.integer_s==1
= one
| x.integer_s== -1
| n.integer_a.[0] bitand 1==0
= one
= ~one
= zero
where
pow :: !Integer !Int -> Integer
pow a b
| b<=2
| b==2
= a * a
= a
# x = pow x (b >> 1)
| b bitand 1==0
= x * x
= a * x * x
negative_power_error
= abort "^ (Integer) called with negative power argument"
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 = {}}
......@@ -84,8 +126,6 @@ instance rem Integer
where
(rem) a b = rem_integer a b
//instance ^ Integer
instance == Integer
where
(==) {integer_s=s1,integer_a=a1} {integer_s=s2,integer_a=a2}
......
......@@ -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 2 ^ 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