summaryrefslogtreecommitdiff
path: root/2.3-1/src/c/auxiliaryFunctions/rand/drands.c
diff options
context:
space:
mode:
authorimushir2016-02-09 16:38:27 +0530
committerimushir2016-02-09 16:38:27 +0530
commita6efab1a42eda8c1e3902c2f2d030a9cb9cfd25e (patch)
tree70d366ae6a84d201f23895071a8064068e77011f /2.3-1/src/c/auxiliaryFunctions/rand/drands.c
parent7bc57b2061931e5b5843ac6616591b7cff9e9476 (diff)
downloadScilab2C-a6efab1a42eda8c1e3902c2f2d030a9cb9cfd25e.tar.gz
Scilab2C-a6efab1a42eda8c1e3902c2f2d030a9cb9cfd25e.tar.bz2
Scilab2C-a6efab1a42eda8c1e3902c2f2d030a9cb9cfd25e.zip
Support for Servo motor for Arduino. Support for'diag' in c
Diffstat (limited to '2.3-1/src/c/auxiliaryFunctions/rand/drands.c')
-rw-r--r--2.3-1/src/c/auxiliaryFunctions/rand/drands.c43
1 files changed, 33 insertions, 10 deletions
diff --git a/2.3-1/src/c/auxiliaryFunctions/rand/drands.c b/2.3-1/src/c/auxiliaryFunctions/rand/drands.c
index 9b7c4cf4..658cd0b0 100644
--- a/2.3-1/src/c/auxiliaryFunctions/rand/drands.c
+++ b/2.3-1/src/c/auxiliaryFunctions/rand/drands.c
@@ -34,37 +34,60 @@ double drands(void) {
if (m2==0){
/* if first entry, compute machine integer word length */
- while (m>m2){
+ while (m>m2){
m2=m;
m=itwo*m2;
+
}
+
halfm = m2;
-
- /* compute multiplier and increment for linear congruential method */
+
+ /* compute multiplier and increment for linear congruential method */
ia = 8*(int)(halfm*atan(1.0)/8.0) + 5;
- ic = 2*(int)(halfm*(0.5-sqrt(3.0)/6.0)) + 1;
- mic = (m2 - ic) + m2;
-
- /* s is the scale factor for converting to floating point */
+
+ ic = 2*(int)(halfm*(0.5-sqrt(3.0)/6.0)) + 1;
+
+ mic = (m2 - ic) + m2;
+
+ /* s is the scale factor for converting to floating point */
s = 0.5/halfm;
+
+
}
/* compute next random number */
iy = iy*ia;
+
+
/* the following statement is for computers which do not allow
integer overflow on addition */
- if (iy > mic) iy = (iy - m2) - m2;
+ if (iy > mic)
+ {
+ iy = (iy - m2) - m2;
+
+ }
iy = iy + ic;
/* the following statement is for computers where the
word length for addition is greater than for multiplication */
- if (iy/2 > m2) iy = (iy - m2) - m2;
+ if (iy/2 > m2)
+ {
+ iy = (iy - m2) - m2;
+
+ }
/* the following statement is for computers where integer
overflow affects the sign bit */
- if (iy < 0) iy = (iy + m2) + m2;
+ if (iy < 0)
+ {
+ iy = (iy + m2) + m2;
+
+
+ }
+
+
return (double)iy*s;
}