From f4f08e09aa28e4c84a70fffb32c703d1c0072462 Mon Sep 17 00:00:00 2001 From: Neil Brown Date: Tue, 27 Jan 2009 13:50:42 +0000 Subject: [PATCH] Fixed the RAN/DRAN intrinsic --- common/Intrinsics.hs | 2 +- support/tock_intrinsics_float.h | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/common/Intrinsics.hs b/common/Intrinsics.hs index 9b8e3ac..b049903 100644 --- a/common/Intrinsics.hs +++ b/common/Intrinsics.hs @@ -79,7 +79,7 @@ intrinsicFunctions = -- Elementary floating point functions -- Appendix N of the occam 2 manual (and section J.4) ++ [(n, ts) | (n, (ts, _)) <- simpleFloatIntrinsics] - ++ [("RAN", ([A.Real32, A.Int32], [(A.Int32, "N")]))] + ++ concatMap doubleD [("RAN", ([A.Real32, A.Int32], [(A.Int32, "N")]))] where query n = (n, ([A.Bool], [(A.Real32, "X")])) simple n = (n, ([A.Real32], [(A.Real32, "X")])) diff --git a/support/tock_intrinsics_float.h b/support/tock_intrinsics_float.h index 1781a31..be0b0ac 100644 --- a/support/tock_intrinsics_float.h +++ b/support/tock_intrinsics_float.h @@ -190,3 +190,9 @@ static inline REAL ADD_PREFIX(SQRT) (REAL X, const char* pos) { } } +static inline REAL ADD_PREFIX(RAN) (RINT, RINT*, const char*) occam_unused; +static inline REAL ADD_PREFIX(RAN) (RINT N, RINT* result1, const char* pos) { + int next = rand_r((unsigned*)&N); + *result1 = *(int*)&N; + return (REAL)next / (REAL)RAND_MAX; +}