KiCad PCB EDA Suite
Loading...
Searching...
No Matches
3d_fastmath.cpp
Go to the documentation of this file.
1
/*
2
* This program source code file is part of KiCad, a free EDA CAD application.
3
*
4
* Copyright (C) 2016 Mario Luzeiro <
[email protected]
>
5
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6
*
7
* This program is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU General Public License
9
* as published by the Free Software Foundation; either version 2
10
* of the License, or (at your option) any later version.
11
*
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
16
*
17
* You should have received a copy of the GNU General Public License
18
* along with this program. If not, see <https://www.gnu.org/licenses/>.
19
*/
20
25
26
27
#include "
3d_fastmath.h
"
28
29
30
// Fast Float Random Numbers
31
// a small and fast implementation for random float numbers in the range [-1,1]
32
// References : Posted by dominik.ries[AT]gmail[DOT]com
33
// http://www.musicdsp.org/showone.php?id=273
34
35
36
// set the initial seed to whatever you like
37
static
int
s_randSeed
= 1;
38
39
// fast rand float, using full 32bit precision
40
// returns in the range [-1, 1] (not confirmed)
41
float
Fast_RandFloat
()
42
{
43
s_randSeed
*= 16807;
44
45
return
(
float
)
s_randSeed
* 4.6566129e-010f;
46
}
47
48
49
// Fast rand, as described here:
50
// http://wiki.osdev.org/Random_Number_Generator
51
52
static
unsigned
long
int
s_nextRandSeed
= 1;
53
54
int
Fast_rand
(
void
)
// RAND_MAX assumed to be 32767
55
{
56
s_nextRandSeed
=
s_nextRandSeed
* 1103515245 + 12345;
57
58
return
(
unsigned
int
)(
s_nextRandSeed
>> 16) & 0x7FFF;
59
}
60
61
void
Fast_srand
(
unsigned
int
seed
)
62
{
63
s_nextRandSeed
=
seed
;
64
}
Fast_RandFloat
float Fast_RandFloat()
Definition
3d_fastmath.cpp:41
s_randSeed
static int s_randSeed
Definition
3d_fastmath.cpp:37
Fast_rand
int Fast_rand(void)
Definition
3d_fastmath.cpp:54
s_nextRandSeed
static unsigned long int s_nextRandSeed
Definition
3d_fastmath.cpp:52
Fast_srand
void Fast_srand(unsigned int seed)
Definition
3d_fastmath.cpp:61
3d_fastmath.h
Defines math related functions.
seed
const uint32_t seed
Definition
test_pip_benchmark.cpp:765
src
3d-viewer
3d_fastmath.cpp
Generated on Fri Jun 26 2026 00:05:31 for KiCad PCB EDA Suite by
1.13.2