Commit 605e6d02 authored by Simon Marlow's avatar Simon Marlow
Browse files

FIX #1254: avoid calling truncate when the result does not fit in the target type

parent 5bbe00bb
......@@ -16,36 +16,45 @@ main =
, 'H' : show ((map floor float_list) :: [Integer])
, 'I' : show ((map floor double_list) :: [Int])
, 'J' : show ((map floor double_list) :: [Integer])
, 'K' : show ((map truncate float_list) :: [Int])
, 'L' : show ((map truncate float_list) :: [Integer])
, 'M' : show ((map truncate double_list) :: [Int])
, 'N' : show ((map truncate double_list) :: [Integer])
{-
, show ((map round float_list) :: [Int])
-}
, 'K' : show ((map truncate small_float_list) :: [Int])
, 'L' : show ((map truncate small_float_list) :: [Integer])
, 'M' : show ((map truncate small_double_list) :: [Int])
, 'N' : show ((map truncate small_double_list) :: [Integer])
, 'n' : show ((map round float_list) :: [Int])
, 'O' : show ((map round float_list) :: [Integer])
, 'P' : show ((map round double_list) :: [Int])
, 'Q' : show ((map round double_list) :: [Integer])
, 'R' : show ((map properFraction float_list) :: [(Int,Float)])
, 'S' : show ((map properFraction float_list) :: [(Integer,Float)])
, 'T' : show (head ((map properFraction double_list) :: [(Int,Double)]))
{-
, show ((map properFraction double_list) :: [(Integer,Double)])
-}
, 'U' : show ((map properFraction double_list) :: [(Integer,Double)])
]
where
float_list :: [Float]
float_list = [
-- these fit into an Int when truncated. Truncation when the
-- result does not fit into the target is undefined - not explicitly
-- so in Haskell 98, but that's the interpretation we've taken in GHC.
-- See bug #1254
small_float_list :: [Float]
small_float_list = [
0.0, -0.0, 1.1, 2.8, 3.5, 4.5, -1.0000000001, -2.9999995,
-3.50000000001, -4.49999999999, 1000012.0, 123.456, 100.25,
102.5, 0.0012, -0.00000012, 1.7e4, -1.7e-4, 0.15e-6, pi,
102.5, 0.0012, -0.00000012, 1.7e4, -1.7e-4, 0.15e-6, pi
]
float_list :: [Float]
float_list = small_float_list ++ [
1.18088e+11, 1.2111e+14
]
double_list :: [Double]
double_list = [
-- these fit into an Int
small_double_list :: [Double]
small_double_list = [
0.0, -0.0, 1.1, 2.8, 3.5, 4.5, -1.0000000001, -2.9999995,
-3.50000000001, -4.49999999999, 1000012.0, 123.456, 100.25,
102.5, 0.0012, -0.00000012, 1.7e4, -1.7e-4, 0.15e-6, pi,
102.5, 0.0012, -0.00000012, 1.7e4, -1.7e-4, 0.15e-6, pi
]
double_list :: [Double]
double_list = small_double_list ++ [
1.18088e+11, 1.2111e+14
]
......@@ -8,13 +8,15 @@ G[0,0,1,2,3,4,-1,-3,-4,-5,1000012,123,100,102,0,-1,17000,-1,0,3,2123882496,51170
H[0,0,1,2,3,4,-1,-3,-4,-5,1000012,123,100,102,0,-1,17000,-1,0,3,118087999488,121109999517696]
I[0,0,1,2,3,4,-2,-3,-4,-5,1000012,123,100,102,0,-1,17000,-1,0,3,2123883008,512187392]
J[0,0,1,2,3,4,-2,-3,-4,-5,1000012,123,100,102,0,-1,17000,-1,0,3,118088000000,121110000000000]
K[0,0,1,2,3,4,-1,-2,-3,-4,1000012,123,100,102,0,0,17000,0,0,3,2123882496,511705088]
L[0,0,1,2,3,4,-1,-2,-3,-4,1000012,123,100,102,0,0,17000,0,0,3,118087999488,121109999517696]
M[0,0,1,2,3,4,-1,-2,-3,-4,1000012,123,100,102,0,0,17000,0,0,3,2123883008,512187392]
N[0,0,1,2,3,4,-1,-2,-3,-4,1000012,123,100,102,0,0,17000,0,0,3,118088000000,121110000000000]
K[0,0,1,2,3,4,-1,-2,-3,-4,1000012,123,100,102,0,0,17000,0,0,3]
L[0,0,1,2,3,4,-1,-2,-3,-4,1000012,123,100,102,0,0,17000,0,0,3]
M[0,0,1,2,3,4,-1,-2,-3,-4,1000012,123,100,102,0,0,17000,0,0,3]
N[0,0,1,2,3,4,-1,-2,-3,-4,1000012,123,100,102,0,0,17000,0,0,3]
n[0,0,1,3,4,4,-1,-3,-4,-4,1000012,123,100,102,0,0,17000,0,0,3,2123882496,511705088]
O[0,0,1,3,4,4,-1,-3,-4,-4,1000012,123,100,102,0,0,17000,0,0,3,118087999488,121109999517696]
P[0,0,1,3,4,4,-1,-3,-4,-4,1000012,123,100,102,0,0,17000,0,0,3,2123883008,512187392]
Q[0,0,1,3,4,4,-1,-3,-4,-4,1000012,123,100,102,0,0,17000,0,0,3,118088000000,121110000000000]
R[(0,0.0),(0,0.0),(1,0.100000024),(2,0.79999995),(3,0.5),(4,0.5),(-1,0.0),(-2,-0.9999995),(-3,-0.5),(-4,-0.5),(1000012,0.0),(123,0.45600128),(100,0.25),(102,0.5),(0,1.2e-3),(0,-1.2e-7),(17000,0.0),(0,-1.7e-4),(0,1.5e-7),(3,0.14159274),(2123882496,0.0),(511705088,0.0)]
S[(0,0.0),(0,0.0),(1,0.100000024),(2,0.79999995),(3,0.5),(4,0.5),(-1,0.0),(-2,-0.9999995),(-3,-0.5),(-4,-0.5),(1000012,0.0),(123,0.45600128),(100,0.25),(102,0.5),(0,1.2e-3),(0,-1.2e-7),(17000,0.0),(0,-1.7e-4),(0,1.5e-7),(3,0.14159274),(118087999488,0.0),(121109999517696,0.0)]
T(0,0.0)
U[(0,0.0),(0,0.0),(1,0.10000000000000009),(2,0.7999999999999998),(3,0.5),(4,0.5),(-1,-1.000000082740371e-10),(-2,-0.9999994999999999),(-3,-0.50000000001),(-4,-0.49999999999),(1000012,0.0),(123,0.45600000000000307),(100,0.25),(102,0.5),(0,1.2e-3),(0,-1.2e-7),(17000,0.0),(0,-1.7e-4),(0,1.5e-7),(3,0.14159265358979312),(118088000000,0.0),(121110000000000,0.0)]
......@@ -8,13 +8,15 @@ G[0,0,1,2,3,4,-1,-3,-4,-5,1000012,123,100,102,0,-1,17000,-1,0,3,118087999488,121
H[0,0,1,2,3,4,-1,-3,-4,-5,1000012,123,100,102,0,-1,17000,-1,0,3,118087999488,121109999517696]
I[0,0,1,2,3,4,-2,-3,-4,-5,1000012,123,100,102,0,-1,17000,-1,0,3,118088000000,121110000000000]
J[0,0,1,2,3,4,-2,-3,-4,-5,1000012,123,100,102,0,-1,17000,-1,0,3,118088000000,121110000000000]
K[0,0,1,2,3,4,-1,-2,-3,-4,1000012,123,100,102,0,0,17000,0,0,3,118087999488,121109999517696]
L[0,0,1,2,3,4,-1,-2,-3,-4,1000012,123,100,102,0,0,17000,0,0,3,118087999488,121109999517696]
M[0,0,1,2,3,4,-1,-2,-3,-4,1000012,123,100,102,0,0,17000,0,0,3,118088000000,121110000000000]
N[0,0,1,2,3,4,-1,-2,-3,-4,1000012,123,100,102,0,0,17000,0,0,3,118088000000,121110000000000]
K[0,0,1,2,3,4,-1,-2,-3,-4,1000012,123,100,102,0,0,17000,0,0,3]
L[0,0,1,2,3,4,-1,-2,-3,-4,1000012,123,100,102,0,0,17000,0,0,3]
M[0,0,1,2,3,4,-1,-2,-3,-4,1000012,123,100,102,0,0,17000,0,0,3]
N[0,0,1,2,3,4,-1,-2,-3,-4,1000012,123,100,102,0,0,17000,0,0,3]
n[0,0,1,3,4,4,-1,-3,-4,-4,1000012,123,100,102,0,0,17000,0,0,3,118087999488,121109999517696]
O[0,0,1,3,4,4,-1,-3,-4,-4,1000012,123,100,102,0,0,17000,0,0,3,118087999488,121109999517696]
P[0,0,1,3,4,4,-1,-3,-4,-4,1000012,123,100,102,0,0,17000,0,0,3,118088000000,121110000000000]
Q[0,0,1,3,4,4,-1,-3,-4,-4,1000012,123,100,102,0,0,17000,0,0,3,118088000000,121110000000000]
R[(0,0.0),(0,0.0),(1,0.100000024),(2,0.79999995),(3,0.5),(4,0.5),(-1,0.0),(-2,-0.9999995),(-3,-0.5),(-4,-0.5),(1000012,0.0),(123,0.45600128),(100,0.25),(102,0.5),(0,1.2e-3),(0,-1.2e-7),(17000,0.0),(0,-1.7e-4),(0,1.5e-7),(3,0.14159274),(118087999488,0.0),(121109999517696,0.0)]
S[(0,0.0),(0,0.0),(1,0.100000024),(2,0.79999995),(3,0.5),(4,0.5),(-1,0.0),(-2,-0.9999995),(-3,-0.5),(-4,-0.5),(1000012,0.0),(123,0.45600128),(100,0.25),(102,0.5),(0,1.2e-3),(0,-1.2e-7),(17000,0.0),(0,-1.7e-4),(0,1.5e-7),(3,0.14159274),(118087999488,0.0),(121109999517696,0.0)]
T(0,0.0)
U[(0,0.0),(0,0.0),(1,0.10000000000000009),(2,0.7999999999999998),(3,0.5),(4,0.5),(-1,-1.000000082740371e-10),(-2,-0.9999994999999999),(-3,-0.50000000001),(-4,-0.49999999999),(1000012,0.0),(123,0.45600000000000307),(100,0.25),(102,0.5),(0,1.2e-3),(0,-1.2e-7),(17000,0.0),(0,-1.7e-4),(0,1.5e-7),(3,0.14159265358979312),(118088000000,0.0),(121110000000000,0.0)]
Supports Markdown
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