Eliminate BC_ENABLE_RAND

It's not needed with a properly seeded PRNG.

Signed-off-by: Gavin Howard <gavin@yzena.com>
computed_goto
Gavin Howard 1 year ago
parent 46bc66f3e6
commit 39b2af3547
Signed by: gavin
GPG Key ID: C08038BDF280D33E
  1. 6
      include/bc.h
  2. 16
      include/lang.h
  3. 16
      include/lex.h
  4. 10
      include/num.h
  5. 4
      include/program.h
  6. 4
      include/rand.h
  7. 36
      src/bc_parse.c
  8. 75
      src/data.c
  9. 4
      src/num.c
  10. 38
      src/program.c
  11. 4
      src/rand.c
  12. 4
      src/vm.c

@ -291,13 +291,13 @@ void bc_lex_token(BcLex *l);
* @return True if @a t should be treated as though it's a variable, false
* otherwise.
*/
#if BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#if BC_ENABLE_EXTRA_MATH
#define BC_PARSE_INST_VAR(t) \
((t) >= BC_INST_VAR && (t) <= BC_INST_SEED && (t) != BC_INST_ARRAY)
#else // BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#else // BC_ENABLE_EXTRA_MATH
#define BC_PARSE_INST_VAR(t) \
((t) >= BC_INST_VAR && (t) <= BC_INST_SCALE && (t) != BC_INST_ARRAY)
#endif // BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#endif // BC_ENABLE_EXTRA_MATH
/**
* Returns true if the previous token @a p (in the form of a bytecode

@ -165,10 +165,10 @@ typedef enum BcInst {
BC_INST_OBASE,
BC_INST_SCALE,
#if BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#if BC_ENABLE_EXTRA_MATH
/// Push the value of the seed global onto the stack.
BC_INST_SEED,
#endif // BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#endif // BC_ENABLE_EXTRA_MATH
/// These are builtin functions.
BC_INST_LENGTH,
@ -176,27 +176,27 @@ typedef enum BcInst {
BC_INST_SQRT,
BC_INST_ABS,
#if BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#if BC_ENABLE_EXTRA_MATH
/// Another builtin function.
BC_INST_IRAND,
#endif // BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#endif // BC_ENABLE_EXTRA_MATH
/// Another builtin function.
BC_INST_READ,
#if BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#if BC_ENABLE_EXTRA_MATH
/// Another builtin function.
BC_INST_RAND,
#endif // BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#endif // BC_ENABLE_EXTRA_MATH
/// Return the max for the various globals.
BC_INST_MAXIBASE,
BC_INST_MAXOBASE,
BC_INST_MAXSCALE,
#if BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#if BC_ENABLE_EXTRA_MATH
/// Return the max value returned by rand().
BC_INST_MAXRAND,
#endif // BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#endif // BC_ENABLE_EXTRA_MATH
/// This is slightly misnamed versus BC_INST_PRINT_POP. Well, it is in bc.
/// dc uses this instruction to print, but not pop. That's valid in dc.

@ -284,10 +284,10 @@ typedef enum BcLexType {
/// bc scale keyword.
BC_LEX_KW_SCALE,
#if BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#if BC_ENABLE_EXTRA_MATH
/// bc seed keyword.
BC_LEX_KW_SEED,
#endif // BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#endif // BC_ENABLE_EXTRA_MATH
/// bc length keyword.
BC_LEX_KW_LENGTH,
@ -301,10 +301,10 @@ typedef enum BcLexType {
/// bc abs keyword.
BC_LEX_KW_ABS,
#if BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#if BC_ENABLE_EXTRA_MATH
/// bc irand keyword.
BC_LEX_KW_IRAND,
#endif // BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#endif // BC_ENABLE_EXTRA_MATH
/// bc quit keyword.
BC_LEX_KW_QUIT,
@ -312,10 +312,10 @@ typedef enum BcLexType {
/// bc read keyword.
BC_LEX_KW_READ,
#if BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#if BC_ENABLE_EXTRA_MATH
/// bc rand keyword.
BC_LEX_KW_RAND,
#endif // BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#endif // BC_ENABLE_EXTRA_MATH
/// bc maxibase keyword.
BC_LEX_KW_MAXIBASE,
@ -326,10 +326,10 @@ typedef enum BcLexType {
/// bc maxscale keyword.
BC_LEX_KW_MAXSCALE,
#if BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#if BC_ENABLE_EXTRA_MATH
/// bc maxrand keyword.
BC_LEX_KW_MAXRAND,
#endif // BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#endif // BC_ENABLE_EXTRA_MATH
/// bc else keyword.
BC_LEX_KW_ELSE,

@ -138,14 +138,8 @@ typedef struct BcNum {
#if BC_ENABLE_EXTRA_MATH
#ifndef BC_ENABLE_RAND
#define BC_ENABLE_RAND (1)
#endif // BC_ENABLE_RAND
#if BC_ENABLE_RAND
// Forward declaration
struct BcRNG;
#endif // BC_ENABLE_RAND
#endif // BC_ENABLE_EXTRA_MATH
@ -516,7 +510,7 @@ BcBigDig bc_num_bigdig2(const BcNum *restrict n);
*/
void bc_num_bigdig2num(BcNum *restrict n, BcBigDig val);
#if BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#if BC_ENABLE_EXTRA_MATH
/**
* Generates a random arbitrary-size integer less than or equal to @a a and
@ -542,7 +536,7 @@ void bc_num_rng(const BcNum *restrict n, struct BcRNG *rng);
*/
void bc_num_createFromRNG(BcNum *restrict n, struct BcRNG *rng);
#endif // BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#endif // BC_ENABLE_EXTRA_MATH
/**
* The add function. This is a BcNumBinaryOp function.

@ -71,12 +71,12 @@ typedef struct BcProgram {
/// The array of globals stacks.
BcVec globals_v[BC_PROG_GLOBALS_LEN];
#if BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#if BC_ENABLE_EXTRA_MATH
/// The pseudo-random number generator.
BcRNG rng;
#endif // BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#endif // BC_ENABLE_EXTRA_MATH
/// The results stack.
BcVec results;

@ -50,8 +50,6 @@
#if BC_ENABLE_EXTRA_MATH
#if BC_ENABLE_RAND
#if BC_ENABLE_LIBRARY
#define BC_RAND_USE_FREE (1)
#else // BC_ENABLE_LIBRARY
@ -516,8 +514,6 @@ void bc_rand_srand(BcRNGData *rng);
/// A reference to a constant multiplier.
extern const BcRandState bc_rand_multiplier;
#endif // BC_ENABLE_RAND
#endif // BC_ENABLE_EXTRA_MATH
#endif // BC_RAND_H

@ -1472,24 +1472,24 @@ static void bc_parse_stmt(BcParse *p) {
case BC_LEX_KW_LENGTH:
case BC_LEX_KW_OBASE:
case BC_LEX_KW_SCALE:
#if BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#if BC_ENABLE_EXTRA_MATH
case BC_LEX_KW_SEED:
#endif // BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#endif // BC_ENABLE_EXTRA_MATH
case BC_LEX_KW_SQRT:
case BC_LEX_KW_ABS:
#if BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#if BC_ENABLE_EXTRA_MATH
case BC_LEX_KW_IRAND:
#endif // BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#endif // BC_ENABLE_EXTRA_MATH
case BC_LEX_KW_READ:
#if BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#if BC_ENABLE_EXTRA_MATH
case BC_LEX_KW_RAND:
#endif // BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#endif // BC_ENABLE_EXTRA_MATH
case BC_LEX_KW_MAXIBASE:
case BC_LEX_KW_MAXOBASE:
case BC_LEX_KW_MAXSCALE:
#if BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#if BC_ENABLE_EXTRA_MATH
case BC_LEX_KW_MAXRAND:
#endif // BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#endif // BC_ENABLE_EXTRA_MATH
{
bc_parse_expr_status(p, BC_PARSE_PRINT, bc_parse_next_expr);
break;
@ -1560,9 +1560,9 @@ static void bc_parse_stmt(BcParse *p) {
bc_vm_printf("BC_STRING_MAX = %lu\n", BC_MAX_STRING);
bc_vm_printf("BC_NAME_MAX = %lu\n", BC_MAX_NAME);
bc_vm_printf("BC_NUM_MAX = %lu\n", BC_MAX_NUM);
#if BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#if BC_ENABLE_EXTRA_MATH
bc_vm_printf("BC_RAND_MAX = %lu\n", BC_MAX_RAND);
#endif // BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#endif // BC_ENABLE_EXTRA_MATH
bc_vm_printf("MAX Exponent = %lu\n", BC_MAX_EXP);
bc_vm_printf("Number of vars = %lu\n", BC_MAX_VARS);
@ -1910,9 +1910,9 @@ static BcParseStatus bc_parse_expr_err(BcParse *p, uint8_t flags,
case BC_LEX_KW_IBASE:
case BC_LEX_KW_LAST:
case BC_LEX_KW_OBASE:
#if BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#if BC_ENABLE_EXTRA_MATH
case BC_LEX_KW_SEED:
#endif // BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#endif // BC_ENABLE_EXTRA_MATH
{
// All of these are leaves and cannot come right after a leaf.
if (BC_ERR(BC_PARSE_LEAF(prev, bin_last, rprn)))
@ -1932,9 +1932,9 @@ static BcParseStatus bc_parse_expr_err(BcParse *p, uint8_t flags,
case BC_LEX_KW_LENGTH:
case BC_LEX_KW_SQRT:
case BC_LEX_KW_ABS:
#if BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#if BC_ENABLE_EXTRA_MATH
case BC_LEX_KW_IRAND:
#endif // BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#endif // BC_ENABLE_EXTRA_MATH
{
// All of these are leaves and cannot come right after a leaf.
if (BC_ERR(BC_PARSE_LEAF(prev, bin_last, rprn)))
@ -1950,15 +1950,15 @@ static BcParseStatus bc_parse_expr_err(BcParse *p, uint8_t flags,
}
case BC_LEX_KW_READ:
#if BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#if BC_ENABLE_EXTRA_MATH
case BC_LEX_KW_RAND:
#endif // BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#endif // BC_ENABLE_EXTRA_MATH
case BC_LEX_KW_MAXIBASE:
case BC_LEX_KW_MAXOBASE:
case BC_LEX_KW_MAXSCALE:
#if BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#if BC_ENABLE_EXTRA_MATH
case BC_LEX_KW_MAXRAND:
#endif // BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#endif // BC_ENABLE_EXTRA_MATH
{
// All of these are leaves and cannot come right after a leaf.
if (BC_ERR(BC_PARSE_LEAF(prev, bin_last, rprn)))

@ -840,27 +840,27 @@ const BcLexKeyword bc_lex_kws[] = {
BC_LEX_KW_ENTRY("ibase", 5, true),
BC_LEX_KW_ENTRY("obase", 5, true),
BC_LEX_KW_ENTRY("scale", 5, true),
#if BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#if BC_ENABLE_EXTRA_MATH
BC_LEX_KW_ENTRY("seed", 4, false),
#endif // BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#endif // BC_ENABLE_EXTRA_MATH
BC_LEX_KW_ENTRY("length", 6, true),
BC_LEX_KW_ENTRY("print", 5, false),
BC_LEX_KW_ENTRY("sqrt", 4, true),
BC_LEX_KW_ENTRY("abs", 3, false),
#if BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#if BC_ENABLE_EXTRA_MATH
BC_LEX_KW_ENTRY("irand", 5, false),
#endif // BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#endif // BC_ENABLE_EXTRA_MATH
BC_LEX_KW_ENTRY("quit", 4, true),
BC_LEX_KW_ENTRY("read", 4, false),
#if BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#if BC_ENABLE_EXTRA_MATH
BC_LEX_KW_ENTRY("rand", 4, false),
#endif // BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#endif // BC_ENABLE_EXTRA_MATH
BC_LEX_KW_ENTRY("maxibase", 8, false),
BC_LEX_KW_ENTRY("maxobase", 8, false),
BC_LEX_KW_ENTRY("maxscale", 8, false),
#if BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#if BC_ENABLE_EXTRA_MATH
BC_LEX_KW_ENTRY("maxrand", 7, false),
#endif // BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#endif // BC_ENABLE_EXTRA_MATH
BC_LEX_KW_ENTRY("else", 4, false),
};
@ -873,7 +873,7 @@ const uint8_t bc_parse_exprs[] = {
BC_PARSE_EXPR_ENTRY(false, false, true, true, true, true, true, true),
BC_PARSE_EXPR_ENTRY(true, true, true, true, true, true, true, true),
BC_PARSE_EXPR_ENTRY(true, true, true, true, true, true, true, true),
#if BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#if BC_ENABLE_EXTRA_MATH
BC_PARSE_EXPR_ENTRY(true, true, true, true, true, true, true, true),
BC_PARSE_EXPR_ENTRY(true, true, false, false, true, true, false, false),
BC_PARSE_EXPR_ENTRY(false, false, false, false, false, true, true, false),
@ -881,14 +881,7 @@ const uint8_t bc_parse_exprs[] = {
BC_PARSE_EXPR_ENTRY(false, true, true, true, true, true, true, false),
BC_PARSE_EXPR_ENTRY(true, true, true, false, true, true, true, true),
BC_PARSE_EXPR_ENTRY(true, true, false, 0, 0, 0, 0, 0)
#elif BC_ENABLE_EXTRA_MATH // BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
BC_PARSE_EXPR_ENTRY(true, true, true, true, true, true, true, true),
BC_PARSE_EXPR_ENTRY(true, true, false, false, true, true, false, false),
BC_PARSE_EXPR_ENTRY(false, false, false, false, false, true, true, false),
BC_PARSE_EXPR_ENTRY(false, false, false, false, false, false, false, false),
BC_PARSE_EXPR_ENTRY(false, true, true, true, true, true, false, true),
BC_PARSE_EXPR_ENTRY(true, false, true, true, true, true, false, 0),
#else // BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#else // BC_ENABLE_EXTRA_MATH
BC_PARSE_EXPR_ENTRY(true, true, true, false, false, true, true, false),
BC_PARSE_EXPR_ENTRY(false, false, false, false, false, false, true, true),
BC_PARSE_EXPR_ENTRY(false, false, false, false, false, false, false, false),
@ -974,11 +967,11 @@ const size_t dc_lex_regs_len = sizeof(dc_lex_regs) / sizeof(uint8_t);
/// not, the character can trivially be replaced by the entry. Positions are
/// kept because it corresponds to the ASCII table.
const uchar dc_lex_tokens[] = {
#if BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#if BC_ENABLE_EXTRA_MATH
BC_LEX_KW_IRAND,
#else // BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#else // BC_ENABLE_EXTRA_MATH
BC_LEX_INVALID,
#endif // BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#endif // BC_ENABLE_EXTRA_MATH
BC_LEX_INVALID,
#if BC_ENABLE_EXTRA_MATH
BC_LEX_OP_TRUNC,
@ -986,11 +979,11 @@ const uchar dc_lex_tokens[] = {
BC_LEX_INVALID,
#endif // BC_ENABLE_EXTRA_MATH
BC_LEX_OP_MODULUS, BC_LEX_INVALID,
#if BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#if BC_ENABLE_EXTRA_MATH
BC_LEX_KW_RAND,
#else // BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#else // BC_ENABLE_EXTRA_MATH
BC_LEX_INVALID,
#endif // BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#endif // BC_ENABLE_EXTRA_MATH
BC_LEX_LPAREN, BC_LEX_RPAREN, BC_LEX_OP_MULTIPLY, BC_LEX_OP_PLUS,
BC_LEX_INVALID, BC_LEX_OP_MINUS, BC_LEX_INVALID, BC_LEX_OP_DIVIDE,
BC_LEX_INVALID, BC_LEX_INVALID, BC_LEX_INVALID, BC_LEX_INVALID,
@ -1011,20 +1004,20 @@ const uchar dc_lex_tokens[] = {
BC_LEX_INVALID,
#endif // BC_ENABLE_EXTRA_MATH
BC_LEX_KW_IBASE,
#if BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#if BC_ENABLE_EXTRA_MATH
BC_LEX_KW_SEED,
#else // BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#else // BC_ENABLE_EXTRA_MATH
BC_LEX_INVALID,
#endif // BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#endif // BC_ENABLE_EXTRA_MATH
BC_LEX_KW_SCALE, BC_LEX_LOAD_POP, BC_LEX_OP_BOOL_AND, BC_LEX_OP_BOOL_NOT,
BC_LEX_KW_OBASE, BC_LEX_PRINT_STREAM, BC_LEX_NQUIT, BC_LEX_POP,
BC_LEX_STORE_PUSH, BC_LEX_KW_MAXIBASE, BC_LEX_KW_MAXOBASE,
BC_LEX_KW_MAXSCALE,
#if BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#if BC_ENABLE_EXTRA_MATH
BC_LEX_KW_MAXRAND,
#else // BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#else // BC_ENABLE_EXTRA_MATH
BC_LEX_INVALID,
#endif // BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#endif // BC_ENABLE_EXTRA_MATH
BC_LEX_SCALE_FACTOR,
BC_LEX_INVALID, BC_LEX_KW_LENGTH, BC_LEX_INVALID, BC_LEX_INVALID,
BC_LEX_INVALID, BC_LEX_OP_POWER, BC_LEX_NEG, BC_LEX_INVALID,
@ -1036,11 +1029,11 @@ const uchar dc_lex_tokens[] = {
BC_LEX_INVALID,
#endif // BC_ENABLE_EXTRA_MATH
BC_LEX_STORE_IBASE,
#if BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#if BC_ENABLE_EXTRA_MATH
BC_LEX_STORE_SEED,
#else // BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#else // BC_ENABLE_EXTRA_MATH
BC_LEX_INVALID,
#endif // BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#endif // BC_ENABLE_EXTRA_MATH
BC_LEX_STORE_SCALE, BC_LEX_LOAD,
BC_LEX_OP_BOOL_OR, BC_LEX_PRINT_POP, BC_LEX_STORE_OBASE, BC_LEX_KW_PRINT,
BC_LEX_KW_QUIT, BC_LEX_SWAP, BC_LEX_OP_ASSIGN, BC_LEX_INVALID,
@ -1089,21 +1082,21 @@ const uchar dc_parse_insts[] = {
BC_INST_INVALID, BC_INST_INVALID, BC_INST_INVALID,
#endif // BC_ENABLED
BC_INST_IBASE, BC_INST_OBASE, BC_INST_SCALE,
#if BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#if BC_ENABLE_EXTRA_MATH
BC_INST_SEED,
#endif // BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#endif // BC_ENABLE_EXTRA_MATH
BC_INST_LENGTH, BC_INST_PRINT,
BC_INST_SQRT, BC_INST_ABS,
#if BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#if BC_ENABLE_EXTRA_MATH
BC_INST_IRAND,
#endif // BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#endif // BC_ENABLE_EXTRA_MATH
BC_INST_QUIT, BC_INST_INVALID,
#if BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#if BC_ENABLE_EXTRA_MATH
BC_INST_RAND,
#endif // BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#endif // BC_ENABLE_EXTRA_MATH
BC_INST_MAXIBASE,
BC_INST_MAXOBASE, BC_INST_MAXSCALE,
#if BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#if BC_ENABLE_EXTRA_MATH
BC_INST_MAXRAND,
#endif // BC_ENABLE_EXTRA_MATH
BC_INST_INVALID,
@ -1122,12 +1115,12 @@ const uchar dc_parse_insts[] = {
#endif // !BC_ENABLE_LIBRARY
#if BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#if BC_ENABLE_EXTRA_MATH
/// A constant for the rand multiplier.
const BcRandState bc_rand_multiplier = BC_RAND_MULTIPLIER;
#endif // BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#endif // BC_ENABLE_EXTRA_MATH
#if BC_LONG_BIT >= 64

@ -3238,7 +3238,7 @@ void bc_num_bigdig2num(BcNum *restrict n, BcBigDig val) {
n->len = i;
}
#if BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#if BC_ENABLE_EXTRA_MATH
void bc_num_rng(const BcNum *restrict n, BcRNG *rng) {
@ -3439,7 +3439,7 @@ void bc_num_irand(BcNum *restrict a, BcNum *restrict b, BcRNG *restrict rng) {
assert(BC_NUM_RDX_VALID(b));
}
#endif // BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#endif // BC_ENABLE_EXTRA_MATH
size_t bc_num_addReq(const BcNum *a, const BcNum *b, size_t scale) {

@ -130,9 +130,9 @@ static void bc_program_prepGlobals(BcProgram *p) {
for (i = 0; i < BC_PROG_GLOBALS_LEN; ++i)
bc_vec_push(p->globals_v + i, p->globals + i);
#if BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#if BC_ENABLE_EXTRA_MATH
bc_rand_push(&p->rng);
#endif // BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#endif // BC_ENABLE_EXTRA_MATH
}
/**
@ -152,9 +152,9 @@ static void bc_program_popGlobals(BcProgram *p, bool reset) {
p->globals[i] = BC_PROG_GLOBAL(v);
}
#if BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#if BC_ENABLE_EXTRA_MATH
bc_rand_pop(&p->rng, reset);
#endif // BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#endif // BC_ENABLE_EXTRA_MATH
}
/**
@ -724,7 +724,7 @@ exec_err:
BC_LONGJMP_CONT;
}
#if BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#if BC_ENABLE_EXTRA_MATH
/**
* Execute a rand().
@ -745,7 +745,7 @@ static void bc_program_rand(BcProgram *p) {
}
#endif // NDEBUG
}
#endif // BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#endif // BC_ENABLE_EXTRA_MATH
/**
* Prints a series of characters, without escapes.
@ -1362,10 +1362,10 @@ static void bc_program_assign(BcProgram *p, uchar inst) {
*ptr = val;
*ptr_t = val;
}
#if BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#if BC_ENABLE_EXTRA_MATH
// To assign to steed, let bc_num_rng() do its magic.
else if (left->t == BC_RESULT_SEED) bc_num_rng(l, &p->rng);
#endif // BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#endif // BC_ENABLE_EXTRA_MATH
BC_SIG_LOCK;
@ -1741,11 +1741,11 @@ static void bc_program_builtin(BcProgram *p, uchar inst) {
bool len = (inst == BC_INST_LENGTH);
// Ensure we have a valid builtin.
#if BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#if BC_ENABLE_EXTRA_MATH
assert(inst >= BC_INST_LENGTH && inst <= BC_INST_IRAND);
#else // BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#else // BC_ENABLE_EXTRA_MATH
assert(inst >= BC_INST_LENGTH && inst <= BC_INST_ABS);
#endif // BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#endif // BC_ENABLE_EXTRA_MATH
#ifndef BC_PROG_NO_STACK_CHECK
// Check stack for dc.
@ -1782,7 +1782,7 @@ static void bc_program_builtin(BcProgram *p, uchar inst) {
BC_NUM_NEG_CLR_NP(res->d.n);
}
#if BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#if BC_ENABLE_EXTRA_MATH
// irand() is easy.
else if (inst == BC_INST_IRAND) {
@ -1794,7 +1794,7 @@ static void bc_program_builtin(BcProgram *p, uchar inst) {
bc_num_irand(num, &res->d.n, &p->rng);
}
#endif // BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#endif // BC_ENABLE_EXTRA_MATH
// Everything else is...not easy.
else {
@ -2330,7 +2330,7 @@ static void bc_program_pushGlobal(BcProgram *p, uchar inst) {
bc_program_pushBigdig(p, p->globals[inst - BC_INST_IBASE], t);
}
#if BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#if BC_ENABLE_EXTRA_MATH
/**
* Pushes the value of seed on the stack.
@ -2353,7 +2353,7 @@ static void bc_program_pushSeed(BcProgram *p) {
bc_num_createFromRNG(&res->d.n, &p->rng);
}
#endif // BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#endif // BC_ENABLE_EXTRA_MATH
/**
* Adds a function to the fns array. The function's ID must have already been
@ -2445,9 +2445,9 @@ void bc_program_free(BcProgram *p) {
if (BC_IS_BC) bc_num_free(&p->last);
#endif // BC_ENABLED
#if BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#if BC_ENABLE_EXTRA_MATH
bc_rand_free(&p->rng);
#endif // BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#endif // BC_ENABLE_EXTRA_MATH
#if DC_ENABLED
if (BC_IS_DC) {
@ -2499,12 +2499,12 @@ void bc_program_init(BcProgram *p) {
}
#endif // DC_ENABLED
#if BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#if BC_ENABLE_EXTRA_MATH
// We need to initialize srand() just in case /dev/urandom and /dev/random
// are not available.
srand((unsigned int) time(NULL));
bc_rand_init(&p->rng);
#endif // BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#endif // BC_ENABLE_EXTRA_MATH
#if BC_ENABLED
if (BC_IS_BC) bc_num_init(&p->last, BC_NUM_DEF_SIZE);

@ -56,7 +56,7 @@
#include <rand.h>
#include <vm.h>
#if BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#if BC_ENABLE_EXTRA_MATH
#if !BC_RAND_BUILTIN
@ -578,4 +578,4 @@ void bc_rand_free(BcRNG *r) {
}
#endif // BC_RAND_USE_FREE
#endif // BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#endif // BC_ENABLE_EXTRA_MATH

@ -1425,9 +1425,9 @@ void bc_vm_init(void) {
vm.maxes[BC_PROG_GLOBALS_OBASE] = BC_MAX_OBASE;
vm.maxes[BC_PROG_GLOBALS_SCALE] = BC_MAX_SCALE;
#if BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#if BC_ENABLE_EXTRA_MATH
vm.maxes[BC_PROG_MAX_RAND] = ((BcRand) 0) - 1;
#endif // BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
#endif // BC_ENABLE_EXTRA_MATH
#if BC_ENABLED
#if !BC_ENABLE_LIBRARY

Loading…
Cancel
Save