pike.git/src/operators.c:110:
else
Pike_error ("Expected integer as string index, got %s.\n",
get_name_of_type (TYPEOF(*ind)));
}
case T_FUNCTION:
case T_PROGRAM:
if (program_index_no_free(to, what, ind)) break;
goto index_error;
- #ifdef AUTO_BIGNUM
+
case T_INT:
if (TYPEOF(*ind) == T_STRING && !IS_UNDEFINED (what)) {
INT_TYPE val = what->u.integer;
convert_svalue_to_bignum(what);
index_no_free(to, what, ind);
if(IS_UNDEFINED(to)) {
if (val) {
Pike_error("Indexing the integer %"PRINTPIKEINT"d "
"with unknown method \"%S\".\n",
val, ind->u.string);
} else {
Pike_error("Indexing the NULL value with \"%S\".\n",
ind->u.string);
}
}
break;
}
/* FALL_THROUGH */
- #endif /* AUTO_BIGNUM */
+
default:
index_error:
if (TYPEOF(*ind) == T_INT)
Pike_error ("Cannot index %s with %"PRINTPIKEINT"d.\n",
(TYPEOF(*what) == T_INT && !what->u.integer)?
"the NULL value":get_name_of_type(TYPEOF(*what)),
ind->u.integer);
else if (TYPEOF(*ind) == T_FLOAT)
Pike_error ("Cannot index %s with %"PRINTPIKEFLOAT"e.\n",
pike.git/src/operators.c:272: Inside #if defined(HAVE_ISINF)
#ifdef HAVE_ISINF
isinf(sp[-1].u.float_number) ||
#endif
#ifdef HAVE_ISNAN
isnan(sp[-1].u.float_number) ||
#endif
0) {
Pike_error("Can't cast infinites or NaN to int.\n");
} else {
int i=DO_NOT_WARN((int)(sp[-1].u.float_number));
- #ifdef AUTO_BIGNUM
+
if((i < 0 ? -i : i) < floor(fabs(sp[-1].u.float_number)))
{
/* Note: This includes the case when i = 0x80000000, i.e.
the absolute value is not computable. */
convert_stack_top_to_bignum();
return; /* FIXME: OK to return? Cast tests below indicates
we have to do this, at least for now... /Noring */
/* Yes, it is ok to return, it is actually an optimization :)
* /Hubbe
*/
}
else
- #endif /* AUTO_BIGNUM */
+
{
SET_SVAL(sp[-1], T_INT, NUMBER_NUMBER, integer, i);
}
}
break;
case T_STRING:
- /* This can be here independently of AUTO_BIGNUM. Besides,
- we really want to reduce the number of number parsers
- around here. :) /Noring */
- #ifdef AUTO_BIGNUM
+
/* The generic function is rather slow, so I added this
* code for benchmark purposes. :-) /per
*/
if( (sp[-1].u.string->len >= 10) || sp[-1].u.string->size_shift )
convert_stack_top_string_to_inumber(10);
else
- #endif /* AUTO_BIGNUM */
+
{
INT_TYPE i = STRTOL(sp[-1].u.string->str, 0, 10);
free_string(sp[-1].u.string);
SET_SVAL(sp[-1], T_INT, NUMBER_NUMBER, integer, i);
}
break;
case PIKE_T_INT:
break;
pike.git/src/operators.c:1724:
}
r = realloc_unlinked_string(r, SUBTRACT_PCHARP(buf, MKPCHARP_STR(r)));
r = low_end_shared_string(r);
pop_n_elems(args);
push_string(r);
break;
}
case BIT_INT:
{
- #ifdef AUTO_BIGNUM
+
int of = 0;
size = 0;
for(e = -args; e < 0; e++)
{
size = DO_INT_TYPE_ADD_OVERFLOW(size, sp[e].u.integer, &of);
}
if(of)
{
convert_svalue_to_bignum(sp-args);
f_add(args);
return;
}
sp-=args;
push_int(size);
- #else
- size=0;
- for(e=-args; e<0; e++) size+=sp[e].u.integer;
- sp-=args-1;
- SET_SVAL(sp[-1], PIKE_T_INT, NUMBER_NUMBER, integer, size);
- #endif /* AUTO_BIGNUM */
+
break;
}
case BIT_FLOAT:
if (args > 2) {
/* Attempt to minimize the accumulated summation error
* by adding the smallest (absolute) values first.
*
* Large accumulated errors can occur eg when the number
* of values to add is of the same order as the largest
pike.git/src/operators.c:2246:
{
SET_SVAL(sp[-2], T_FLOAT, 0, float_number, (FLOAT_TYPE)sp[-2].u.integer);
return 1;
}
else if(TYPEOF(sp[-1]) == T_INT && TYPEOF(sp[-2]) == T_FLOAT)
{
SET_SVAL(sp[-1], T_FLOAT, 0, float_number, (FLOAT_TYPE)sp[-1].u.integer);
return 1;
}
- #ifdef AUTO_BIGNUM
+
if(is_bignum_object_in_svalue(sp-2) && TYPEOF(sp[-1]) == T_FLOAT)
{
stack_swap();
ref_push_type_value(float_type_string);
stack_swap();
f_cast();
stack_swap();
return 1;
}
else if(is_bignum_object_in_svalue(sp-1) && TYPEOF(sp[-2]) == T_FLOAT)
{
ref_push_type_value(float_type_string);
stack_swap();
f_cast();
return 1;
}
- #endif
+
return 0;
}
static int call_lfun(int left, int right)
{
struct object *o;
struct program *p;
int i;
if(TYPEOF(sp[-2]) == T_OBJECT &&
pike.git/src/operators.c:2402:
push_multiset(l);
return;
}
case T_FLOAT:
sp--;
sp[-1].u.float_number -= sp[0].u.float_number;
return;
case T_INT:
- #ifdef AUTO_BIGNUM
+
if(INT_TYPE_SUB_OVERFLOW(sp[-2].u.integer, sp[-1].u.integer))
{
convert_stack_top_to_bignum();
f_minus(2);
return;
}
- #endif /* AUTO_BIGNUM */
+
sp--;
SET_SVAL(sp[-1], PIKE_T_INT, NUMBER_NUMBER, integer,
sp[-1].u.integer - sp[0].u.integer);
return;
case T_STRING:
{
struct pike_string *s,*ret;
s=make_shared_string("");
ret=string_replace(sp[-2].u.string,sp[-1].u.string,s);
pike.git/src/operators.c:3423:
modify_stack_depth(-1);
return 1;
default:
return 0;
}
}
PMOD_EXPORT void o_lsh(void)
{
- #ifdef AUTO_BIGNUM
+
if ((TYPEOF(sp[-1]) == T_INT) && (TYPEOF(sp[-2]) == T_INT) &&
INT_TYPE_LSH_OVERFLOW(sp[-2].u.integer, sp[-1].u.integer))
convert_stack_top_to_bignum();
- #endif /* AUTO_BIGNUM */
+
if(TYPEOF(sp[-1]) != T_INT || TYPEOF(sp[-2]) != T_INT)
{
int args = 2;
if(call_lfun(LFUN_LSH, LFUN_RLSH))
return;
if(TYPEOF(sp[-2]) != T_INT)
SIMPLE_BAD_ARG_ERROR("`<<", 1, "int|object");
SIMPLE_BAD_ARG_ERROR("`<<", 2, "int(0..)|object");
}
- #ifndef AUTO_BIGNUM
- if (sp[-1].u.integer > 31) {
- sp--;
- SET_SVAL(sp[-1], T_INT, NUMBER_NUMBER, integer, 0);
- return;
- }
- #endif /* !AUTO_BIGNUM */
+
if (sp[-1].u.integer < 0) {
int args = 2;
SIMPLE_BAD_ARG_ERROR("`<<", 2, "int(0..)|object");
}
sp--;
SET_SVAL(sp[-1], T_INT, NUMBER_NUMBER, integer,
sp[-1].u.integer << sp->u.integer);
}
/*! @decl int `<<(int arg1, int arg2)
pike.git/src/operators.c:3515:
if(TYPEOF(sp[-2]) != T_INT)
SIMPLE_BAD_ARG_ERROR("`>>", 1, "int|object");
SIMPLE_BAD_ARG_ERROR("`>>", 2, "int(0..)|object");
}
if (sp[-1].u.integer < 0) {
int args = 2;
SIMPLE_BAD_ARG_ERROR("`>>", 2, "int(0..)|object");
}
- if(
- #ifdef AUTO_BIGNUM
- (INT_TYPE_RSH_OVERFLOW(sp[-2].u.integer, sp[-1].u.integer))
- #else /* !AUTO_BIGNUM */
- (sp[-1].u.integer > 31)
- #endif /* AUTO_BIGNUM */
- )
+ if( INT_TYPE_RSH_OVERFLOW(sp[-2].u.integer, sp[-1].u.integer) )
{
sp--;
if (sp[-1].u.integer < 0) {
SET_SVAL(sp[-1], T_INT, NUMBER_NUMBER, integer, -1);
} else {
SET_SVAL(sp[-1], T_INT, NUMBER_NUMBER, integer, 0);
}
return;
}
pike.git/src/operators.c:3747:
case TWO_TYPES(T_INT,T_FLOAT):
sp--;
sp[-1].u.float_number=
(FLOAT_TYPE) sp[-1].u.integer * sp[0].u.float_number;
SET_SVAL_TYPE(sp[-1], T_FLOAT);
return;
case TWO_TYPES(T_INT,T_INT):
{
INT_TYPE res;
- #ifndef AUTO_BIGNUM
- res = sp[-2].u.integer * sp[-1].u.integer;
- #else
+
int of = 0;
res = DO_INT_TYPE_MUL_OVERFLOW(sp[-2].u.integer, sp[-1].u.integer, &of);
if(of)
{
convert_stack_top_to_bignum();
goto do_lfun_multiply;
}
- #endif /* AUTO_BIGNUM */
+
sp--;
SET_SVAL(sp[-1], T_INT, NUMBER_NUMBER, integer, res);
return;
}
default:
do_lfun_multiply:
if(call_lfun(LFUN_MULTIPLY, LFUN_RMULTIPLY))
return;
PIKE_ERROR("`*", "Bad arguments.\n", sp, 2);
pike.git/src/operators.c:4100:
case T_INT:
{
INT_TYPE tmp;
if (sp[-1].u.integer == 0)
OP_DIVISION_BY_ZERO_ERROR("`/");
if(INT_TYPE_DIV_OVERFLOW(sp[-2].u.integer, sp[-1].u.integer))
{
- #ifdef AUTO_BIGNUM
+
stack_swap();
convert_stack_top_to_bignum();
stack_swap();
goto do_lfun_division;
- #else
- /* It's not possible to do MININT/-1 (it gives FPU exception on
- some CPU:s), thus we return what MININT*-1 returns: MININT. */
- tmp = sp[-2].u.integer;
- #endif /* AUTO_BIGNUM */
+
}
else
tmp = sp[-2].u.integer/sp[-1].u.integer;
sp--;
/* What is this trying to solve? /Noring */
/* It fixes rounding towards negative infinity. /mast */
if((sp[-1].u.integer<0) != (sp[0].u.integer<0))
if(tmp*sp[0].u.integer!=sp[-1].u.integer)
tmp--;
pike.git/src/operators.c:4237:
modify_stack_depth(-1);
return 1;
}
return 0;
}
PMOD_EXPORT void o_mod(void)
{
if(TYPEOF(sp[-2]) != TYPEOF(sp[-1]) && !float_promote())
{
- #ifdef AUTO_BIGNUM
+
do_lfun_modulo:
- #endif
+
if(call_lfun(LFUN_MOD, LFUN_RMOD))
return;
switch(TWO_TYPES(TYPEOF(sp[-2]), TYPEOF(sp[-1])))
{
case TWO_TYPES(T_STRING,T_INT):
{
struct pike_string *s=sp[-2].u.string;
ptrdiff_t tmp,base;
pike.git/src/operators.c:4345:
/* res = b+~((~a) % b) */
res = DO_INT_TYPE_MOD_OVERFLOW(~a, b, &of);
res = DO_INT_TYPE_ADD_OVERFLOW(b, ~res, &of);
}else{
/* a % b and a % -b are equivalent, if overflow does not
* happen
* res = -(-a % -b) = a % b; */
res = DO_INT_TYPE_MOD_OVERFLOW(a, b, &of);
}
}
- #ifdef AUTO_BIGNUM
+
if (of) {
stack_swap();
convert_stack_top_to_bignum();
stack_swap();
goto do_lfun_modulo;
}
- #endif
+
sp--;
SET_SVAL(sp[-1], T_INT, NUMBER_NUMBER, integer, res);
return;
}
default:
PIKE_ERROR("`%", "Bad argument 1.\n", sp, 2);
}
}
/*! @decl mixed `%(object arg1, mixed arg2)
pike.git/src/operators.c:4651:
case T_OBJECT:
do_lfun_negate:
CALL_OPERATOR(LFUN_SUBTRACT,1);
break;
case T_FLOAT:
sp[-1].u.float_number=-sp[-1].u.float_number;
return;
case T_INT:
- #ifdef AUTO_BIGNUM
+
if(INT_TYPE_NEG_OVERFLOW(sp[-1].u.integer))
{
convert_stack_top_to_bignum();
goto do_lfun_negate;
}
- #endif /* AUTO_BIGNUM */
+
SET_SVAL(sp[-1], T_INT, NUMBER_NUMBER, integer, -sp[-1].u.integer);
return;
default:
PIKE_ERROR("`-", "Bad argument to unary minus.\n", sp, 1);
}
}
static void string_or_array_range (int bound_types,
struct svalue *ind,