Skip to content

Instantly share code, notes, and snippets.

@mightybyte
Created December 18, 2015 00:06
Show Gist options
  • Save mightybyte/6793a5b18ee002aa2dad to your computer and use it in GitHub Desktop.
Save mightybyte/6793a5b18ee002aa2dad to your computer and use it in GitHub Desktop.
diff -r clock-0.5.1 clock-0.5.2
diff -r clock-0.5.1/System/Clock.hsc clock-0.5.2/System/Clock.hsc
173,177c173,175
< normalize (TimeSpec xs xn)
< | xn < 0 || xn >= 10^9 =
< let (q, r) = xn `divMod` (10^9)
< in TimeSpec (xs + q) r
< | otherwise = TimeSpec xs xn
---
> normalize (TimeSpec xs xn) | xn < 0 || xn >= 10^9 = TimeSpec (xs + q) r
> | otherwise = TimeSpec xs xn
> where (q, r) = xn `divMod` (10^9)
180,197c178,185
< (TimeSpec xs xn) + (TimeSpec ys yn) =
< normalize $ TimeSpec (xs + ys) (xn + yn)
< (TimeSpec xs xn) - (TimeSpec ys yn) =
< normalize $ TimeSpec (xs - ys) (xn - yn)
< (normalize -> TimeSpec xs xn) * (normalize -> TimeSpec ys yn) =
< let
< -- convert to arbitraty Integer type to avoid int overflow
< xsi = toInteger xs
< xni = toInteger xn
< ysi = toInteger ys
< yni = toInteger yn
< in
< normalize $ TimeSpec
< -- seconds
< (fromInteger $ xsi * ysi)
< -- nanoseconds
< (fromInteger $ (xni * yni + (xni * ysi + xsi * yni) * (10^9))
< `div` (10^9))
---
> (TimeSpec xs xn) + (TimeSpec ys yn) = normalize $ TimeSpec (xs + ys) (xn + yn)
> (TimeSpec xs xn) - (TimeSpec ys yn) = normalize $ TimeSpec (xs - ys) (xn - yn)
> (TimeSpec xs xn) * (TimeSpec ys yn) =
> let xsi = toInteger xs -- convert to arbitraty Integer type to avoid int overflow
> xni = toInteger xn
> ysi = toInteger ys
> yni = toInteger yn -- seconds -- nanoseconds
> in normalize $! TimeSpec (fromInteger $! xsi * ysi) (fromInteger $! (xni * yni + (xni * ysi + xsi * yni) * (10^9)) `div` (10^9))
200,209c188,192
< abs (normalize -> TimeSpec xs xn)
< | xs == 0 = normalize $ TimeSpec 0 xn
< | otherwise = normalize $ TimeSpec (abs xs) (signum xs * xn)
< signum (normalize -> TimeSpec xs xn)
< | xs == 0 = TimeSpec (signum xn) 0
< | otherwise = TimeSpec (signum xs) 0
< fromInteger x =
< -- For range, compute div, mod over integers, not any bounded type.
< let (q, r) = x `divMod` (10^9)
< in TimeSpec (fromInteger q) (fromInteger r)
---
> abs (normalize -> TimeSpec xs xn) | xs == 0 = normalize $! TimeSpec 0 xn
> | otherwise = normalize $! TimeSpec (abs xs) (signum xs * xn)
> signum (normalize -> TimeSpec xs xn) | xs == 0 = TimeSpec (signum xn) 0
> | otherwise = TimeSpec (signum xs) 0
> --fromInteger x = TimeSpec (fromInteger q) (fromInteger r) where (q, r) = x `divMod` (10^9)
diff -r clock-0.5.1/clock.cabal clock-0.5.2/clock.cabal
2c2
< version: 0.5.1
---
> version: 0.5.2
27a28,29
> Removed fromInteger definition for TimeSpec, Cetin Sert on 2015-12-15.
> .
33c35
< copyright: Copyright © Cetin Sert 2009-2013, Eugene Kirpichov 2010, Finn Espen Gundersen 2013, Gerolf Seitz 2013, Mathieu Boespflug 2014 2015, Chris Done 2015, Dimitri Sabadie 2015, Christian Burger 2015
---
> copyright: Copyright © Cetin Sert 2009-2016, Eugene Kirpichov 2010, Finn Espen Gundersen 2013, Gerolf Seitz 2013, Mathieu Boespflug 2014 2015, Chris Done 2015, Dimitri Sabadie 2015, Christian Burger 2015
70c72
< ghc-options: -O2 -Wall
---
> ghc-options: -O3 -Wall
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment