Commit 18b5f2e7 authored by Mart Lubbers's avatar Mart Lubbers

Merge branch 'limits' into 'master'

use limits for integer & reals from Data.Int/Real

See merge request !31
parents 760387ac b1f32ec0
Pipeline #33267 passed with stage
in 1 minute and 5 seconds
......@@ -63,6 +63,4 @@ derive ggen (), (,), (,,), (,,,), (,,,,), (,,,,,), (,,,,,,), (,,,,,,,)
derive ggen [], [!], [ !], [!!]
derive ggen {}, {!}
maxint :: Int
minint :: Int
defaultMaxStrLen :== 16384
......@@ -11,7 +11,7 @@ implementation module Gast.Gen
pieter@cs.ru.nl
*/
import StdEnv, StdFunc, StdGeneric, Math.Random, Data.Maybe, Data.Functor, Data.List
import StdEnv, StdFunc, StdGeneric, Math.Random, Data.Maybe, Data.Functor, Data.List, Data.Int, Data.Real
from Data.Set import :: Set
import qualified Data.Set
from Data.Map import :: Map, instance Functor (Map k)
......@@ -44,16 +44,10 @@ where
= rand x rnd m [a:l]
// -------
maxint :: Int
maxint =: IF_INT_64_OR_32 (2^63-1) (2^31-1) //2147483647
minint :: Int
minint =: IF_INT_64_OR_32 (2^63) (2^31) //-2147483648
genState :: GenState
genState =
{ depth = 0
, maxDepth = maxint
, maxDepth = LargestInt
, maxStringLength = defaultMaxStrLen
, path = []
, mode = SkewGeneration { skewl = 1
......@@ -111,11 +105,11 @@ where
// ================= generic generation ================= //
ggen{|Int|} s = [0: interleave [i \\ n <- [1..(s.maxDepth - s.depth)], i <- [n,~n]] (if (s.maxDepth == maxint) [maxint,minint,maxint-1,minint+1] [])]
ggen{|Int|} s = [0: interleave [i \\ n <- [1..(s.maxDepth - s.depth)], i <- [n,~n]] (if (s.maxDepth == LargestInt) [LargestInt,SmallestInt,LargestInt - 1, SmallestInt + 1] [])]
ggen{|Bool|} s = [False,True]
ggen{|Char|} s = take (s.maxDepth - s.depth) (interleave ['a'..'~'] (interleave ['A'..'`'] (interleave (map toChar [32..64]) ['\t\n\r'])))
ggen{|Real|} s
| s.maxDepth < maxint
| s.maxDepth < LargestInt
= takeWhile (\r -> abs r <= toReal (s.maxDepth - s.depth)) l
= l
where
......@@ -124,13 +118,12 @@ where
[r \\ x <- diag [1:prims] [1:prims] (\n d.toReal n/toReal d), r <- [x,~ x]]
(interleave
[r \\ x <- map sqrt [2.0..], r <- [x, ~x]]
(if (s.maxDepth == maxint)
[5.0E-324, 2.2250738585072009E-308, 2.2250738585072014E-308,maxDouble: largeReals (maxDouble/2.0)] // double precision
(if (s.maxDepth == LargestInt)
[5.0E-324, 2.2250738585072009E-308, LowestReal, LargestReal: largeReals (LargestReal/2.0)] // double precision
[]
)
)
]
maxDouble = 1.7976931348623157E308
largeReals r
| r < 10.0
= []
......
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