src/Tools/Metis/src/PortableMlton.sml
changeset 25430 372d6749f00e
parent 24316 3880d21d6013
child 39353 7f11d833d65b
equal deleted inserted replaced
25429:9e14fbd43e6b 25430:372d6749f00e
    17 (* ------------------------------------------------------------------------- *)
    17 (* ------------------------------------------------------------------------- *)
    18 
    18 
    19 val pointerEqual = MLton.eq;
    19 val pointerEqual = MLton.eq;
    20 
    20 
    21 (* ------------------------------------------------------------------------- *)
    21 (* ------------------------------------------------------------------------- *)
    22 (* Timing function applications a la Mosml.time.                             *)
    22 (* Timing function applications.                                             *)
    23 (* ------------------------------------------------------------------------- *)
    23 (* ------------------------------------------------------------------------- *)
    24 
    24 
    25 fun time f x =
    25 fun time f x =
    26     let
    26     let
    27       fun p t =
    27       fun p t =
    60 (* Critical section markup (multiprocessing)                                 *)
    60 (* Critical section markup (multiprocessing)                                 *)
    61 (* ------------------------------------------------------------------------- *)
    61 (* ------------------------------------------------------------------------- *)
    62 
    62 
    63 fun CRITICAL e = e ();     (*dummy*)
    63 fun CRITICAL e = e ();     (*dummy*)
    64 
    64 
       
    65 (* ------------------------------------------------------------------------- *)
       
    66 (* Generating random values.                                                 *)
       
    67 (* ------------------------------------------------------------------------- *)
       
    68 
       
    69 fun randomWord () = MLton.Random.rand ();
       
    70 
       
    71 fun randomBool () = Word.andb (randomWord (),0w1) = 0w0;
       
    72 
       
    73 fun randomInt 1 = 0
       
    74   | randomInt 2 = Word.toInt (Word.andb (randomWord (), 0w1))
       
    75   | randomInt 4 = Word.toInt (Word.andb (randomWord (), 0w3))
       
    76   | randomInt n = Word.toInt (Word.mod (randomWord (), Word.fromInt n));
       
    77 
       
    78 local
       
    79   fun wordToReal w = Real.fromInt (Word.toInt (Word.>> (w,0w1)))
       
    80 
       
    81   val normalizer = 1.0 / wordToReal (Word.notb 0w0);
       
    82 in
       
    83   fun randomReal () = normalizer * wordToReal (randomWord ());
       
    84 end;
       
    85 
    65 end
    86 end
    66 
    87 
    67 (* ------------------------------------------------------------------------- *)
    88 (* ------------------------------------------------------------------------- *)
    68 (* Quotations a la Moscow ML.                                                *)
    89 (* Quotations a la Moscow ML.                                                *)
    69 (* ------------------------------------------------------------------------- *)
    90 (* ------------------------------------------------------------------------- *)