1 /*
2 * Copyright (c) 2017, NVIDIA CORPORATION. All rights reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
17
18 /* clang-format off */
19
20 /* rand3f.c - Implements LIB3F rand subprogram. */
21
22 #include "ent3f.h"
23
24 /* drand48 is not currently available on win64 */
25 #if defined(WIN64) || defined(WIN32)
26
27 #include <stdlib.h>
28
ENT3F(RAND1,rand1)29 float ENT3F(RAND1, rand1)()
30 {
31 float scale, base, fine;
32
33 scale = RAND_MAX + 1.0;
34 base = rand() / scale;
35 fine = rand() / scale;
36 return base + fine / scale;
37 }
38
ENT3F(RAND2,rand2)39 float ENT3F(RAND2, rand2)(int *flag)
40 {
41 float scale, base, fine;
42
43 if (*flag)
44 srand(*flag);
45 scale = RAND_MAX + 1.0;
46 base = rand() / scale;
47 fine = rand() / scale;
48 return base + fine / scale;
49 }
50 #else
51
52 extern double drand48();
53
ENT3F(RAND,rand)54 double ENT3F(RAND, rand)(void) { return drand48(); }
55
56 #endif
57