mirror of
https://github.com/rfivet/uemacs.git
synced 2024-12-18 07:16:23 -05:00
Clean up abs usage versus implementation.
Clarify ernd() behaviour.
This commit is contained in:
parent
83b4028c95
commit
8aeb526a2a
12
estruct.h
12
estruct.h
@ -183,12 +183,6 @@
|
||||
#define poke(a,b,c,d) movedata(FP_SEG(c),FP_OFF(c),a,b,d)
|
||||
#endif
|
||||
|
||||
#if VMS
|
||||
#define atoi xatoi
|
||||
#define abs xabs
|
||||
#define getname xgetname
|
||||
#endif
|
||||
|
||||
#if MSDOS & MSC
|
||||
#include <dos.h>
|
||||
#include <memory.h>
|
||||
@ -215,12 +209,6 @@
|
||||
#define ENVFUNC 0
|
||||
#endif
|
||||
|
||||
/* Internal defined functions */
|
||||
|
||||
#ifdef abs
|
||||
#undef abs
|
||||
#endif
|
||||
|
||||
/* DIFCASE represents the integer difference between upper
|
||||
and lower case letters. It is an xor-able value, which is
|
||||
fortunate, since the relative positions of upper to lower
|
||||
|
30
eval.c
30
eval.c
@ -288,7 +288,7 @@ static int putctext( char *iline)
|
||||
static char *result ; /* string result */
|
||||
static int ressize = 0 ; /* mark result as uninitialized */
|
||||
|
||||
static int ernd( void) ;
|
||||
static int ernd( int i) ;
|
||||
static int sindex( char *source, char *pattern) ;
|
||||
static char *xlat( char *source, char *lookup, char *trans) ;
|
||||
|
||||
@ -537,13 +537,7 @@ static char *gtfun( char *fname) {
|
||||
retstr = result ;
|
||||
break ;
|
||||
case UFRND | MONAMIC:
|
||||
sz = atoi( arg1) ;
|
||||
if( sz == 0)
|
||||
sz = ernd() ;
|
||||
else
|
||||
sz = ernd() % abs( sz) + 1 ;
|
||||
|
||||
retstr = i_to_a( sz) ;
|
||||
retstr = i_to_a( ernd( atoi( arg1))) ;
|
||||
break ;
|
||||
case UFABS | MONAMIC:
|
||||
retstr = i_to_a( abs( atoi( arg1))) ;
|
||||
@ -1311,21 +1305,21 @@ char *mklower(char *str)
|
||||
return str;
|
||||
}
|
||||
|
||||
/*
|
||||
* take the absolute value of an integer
|
||||
*/
|
||||
int abs(int x)
|
||||
{
|
||||
return x < 0 ? -x : x;
|
||||
}
|
||||
|
||||
/*
|
||||
* returns a random integer
|
||||
* ernd( 0) [ 0 .. 2147483647]
|
||||
* ernd( i) [ 1 .. abs( i)]
|
||||
* ernd( 1) [ 1]
|
||||
* ernd( -2147483648) [ 1 .. 2147483647] actually 2147482413
|
||||
*/
|
||||
static int ernd( void) {
|
||||
static int ernd( int i) {
|
||||
seed = seed * 1721 + 10007 ;
|
||||
seed &= ~(1 << 31) ; /* abs() introduces 176719 periodicity */
|
||||
seed &= ~(1 << 31) ; /* avoid abs() which introduces 176719 periodicity */
|
||||
if( i == 0)
|
||||
return seed ;
|
||||
|
||||
i = i < 0 ? -i : i ; /* abs( i) */
|
||||
return seed % i + 1 ;
|
||||
}
|
||||
|
||||
/*
|
||||
|
Loading…
Reference in New Issue
Block a user