1 /*************************************************************************
3 * Open Dynamics Engine, Copyright (C) 2001,2002 Russell L. Smith. *
4 * All rights reserved. Email: russ@q12.org Web: www.q12.org *
6 * This library is free software; you can redistribute it and/or *
7 * modify it under the terms of EITHER: *
8 * (1) The GNU Lesser General Public License as published by the Free *
9 * Software Foundation; either version 2.1 of the License, or (at *
10 * your option) any later version. The text of the GNU Lesser *
11 * General Public License is included with this library in the *
13 * (2) The BSD-style license that is included with this library in *
14 * the file LICENSE-BSD.TXT. *
16 * This library is distributed in the hope that it will be useful, *
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files *
19 * LICENSE.TXT and LICENSE-BSD.TXT for more details. *
21 *************************************************************************/
23 #include <ode/config.h>
25 #include <ode/matrix.h>
27 //****************************************************************************
30 static unsigned long seed = 0;
34 seed = (1664525L*seed + 1013904223L) & 0xffffffff;
39 unsigned long dRandGetSeed()
45 void dRandSetSeed (unsigned long s)
53 unsigned long oldseed = seed;
56 if (dRand() != 0x3c6ef35f || dRand() != 0x47502932 ||
57 dRand() != 0xd1ccf6e9 || dRand() != 0xaaf95334 ||
58 dRand() != 0x6252e503) ret = 0;
66 double a = double(n) / 4294967296.0;
67 return (int) (double(dRand()) * a);
73 return ((dReal) dRand()) / ((dReal) 0xffffffff);
76 //****************************************************************************
77 // matrix utility stuff
79 void dPrintMatrix (dReal *A, int n, int m, char *fmt, FILE *f)
84 for (j=0; j<m; j++) fprintf (f,fmt,A[i*skip+j]);
90 void dMakeRandomVector (dReal *A, int n, dReal range)
93 for (i=0; i<n; i++) A[i] = (dRandReal()*REAL(2.0)-REAL(1.0))*range;
97 void dMakeRandomMatrix (dReal *A, int n, int m, dReal range)
102 for (i=0; i<n; i++) {
103 for (j=0; j<m; j++) A[i*skip+j] = (dRandReal()*REAL(2.0)-REAL(1.0))*range;
108 void dClearUpperTriangle (dReal *A, int n)
112 for (i=0; i<n; i++) {
113 for (j=i+1; j<n; j++) A[i*skip+j] = 0;
118 dReal dMaxDifference (const dReal *A, const dReal *B, int n, int m)
124 for (i=0; i<n; i++) {
125 for (j=0; j<m; j++) {
126 diff = dFabs(A[i*skip+j] - B[i*skip+j]);
127 if (diff > max) max = diff;
134 dReal dMaxDifferenceLowerTriangle (const dReal *A, const dReal *B, int n)
140 for (i=0; i<n; i++) {
141 for (j=0; j<=i; j++) {
142 diff = dFabs(A[i*skip+j] - B[i*skip+j]);
143 if (diff > max) max = diff;