mirror of
https://github.com/Stichting-MINIX-Research-Foundation/pkgsrc-ng.git
synced 2025-08-03 17:59:07 -04:00
46 lines
1.1 KiB
Plaintext
46 lines
1.1 KiB
Plaintext
$NetBSD: patch-ac,v 1.2 2013/04/01 07:35:04 sbd Exp $
|
|
|
|
--- zerandom.c.orig 1998-11-24 05:08:12.000000000 +0000
|
|
+++ zerandom.c
|
|
@@ -3,7 +3,11 @@
|
|
As a special restriction the file must not be used in this or a modified
|
|
form on Microsoft and Be systems. */
|
|
|
|
+#ifdef __linux__
|
|
#include <ieee754.h>
|
|
+#else
|
|
+#include <machine/ieee.h>
|
|
+#endif
|
|
#include <stdlib.h>
|
|
|
|
#include "zelibm.h"
|
|
@@ -15,15 +19,28 @@ zerandom (double low, double high)
|
|
/* Get two 31 bit random numbers for the initial mantissa. */
|
|
unsigned int r1 = random ();
|
|
unsigned int r2 = random ();
|
|
+#ifdef __linux__
|
|
union ieee754_double u;
|
|
+#else
|
|
+ union ieee_double_u u;
|
|
+#endif
|
|
double res;
|
|
|
|
+#ifdef __linux__
|
|
u.ieee.negative = 0;
|
|
u.ieee.exponent = IEEE754_DOUBLE_BIAS - 1;
|
|
u.ieee.mantissa0 = r1 >> 1;
|
|
u.ieee.mantissa1 = r2 | r1 << 31;
|
|
|
|
res = low + 2 * (u.d - 0.5) * (high - low);
|
|
+#else
|
|
+ u.dblu_dbl.dbl_sign = 0;
|
|
+ u.dblu_dbl.dbl_exp = DBL_EXP_BIAS - 1;
|
|
+ u.dblu_dbl.dbl_frach = r1 >> 1;
|
|
+ u.dblu_dbl.dbl_fracl = r2 | r1 << 31;
|
|
+
|
|
+ res = low + 2 * (u.dblu_d - 0.5) * (high - low);
|
|
+#endif
|
|
|
|
while (res > high)
|
|
res /= 2.0;
|