Skip to content
Snippets Groups Projects
Commit 6e110fe4 authored by Ben Gamari's avatar Ben Gamari :turtle:
Browse files

Fix overflow check

As akio points out, the fix to #229 which I authored previously was blatantly
wrong.
parent b8a8d09d
No related branches found
No related tags found
No related merge requests found
......@@ -32,7 +32,7 @@ import GHC.Arr ( STArray )
import qualified GHC.Arr as Arr
import qualified GHC.Arr as ArrST
import GHC.ST ( ST(..), runST )
import GHC.Base ( IO(..) )
import GHC.Base ( IO(..), divInt# )
import GHC.Exts
import GHC.Ptr ( nullPtr, nullFunPtr )
import GHC.Stable ( StablePtr(..) )
......@@ -1370,10 +1370,12 @@ fLOAT_SCALE n# = safe_scale scale# n# where !(I# scale#) = SIZEOF_HSFLOAT
safe_scale :: Int# -> Int# -> Int#
safe_scale scale# n#
| isTrue# (res# >=# n#) = res#
| otherwise = error "Data.Array.Base.safe_scale: Overflow"
| not overflow = res#
| otherwise = error "Data.Array.Base.safe_scale: Overflow"
where
!res# = scale# *# n#
!overflow = isTrue# (maxN# `divInt#` scale# <# n#)
!(I# maxN#) = maxBound
bOOL_INDEX :: Int# -> Int#
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment