pike.git
/
src
/
operators.c
version
»
Context lines:
10
20
40
80
file
none
3
pike.git/src/operators.c:1:
/* || This file is part of Pike. For copyright information see COPYRIGHT. || Pike is distributed under GPL, LGPL and MPL. See the file COPYING || for more information.
-
|| $Id: operators.c,v 1.
183
2003/11/13
21
:
55
:
34
mast Exp $
+
|| $Id: operators.c,v 1.
184
2003/11/13
22
:
27
:
59
mast Exp $
*/ #include "global.h" #include <math.h>
-
RCSID("$Id: operators.c,v 1.
183
2003/11/13
21
:
55
:
34
mast Exp $");
+
RCSID("$Id: operators.c,v 1.
184
2003/11/13
22
:
27
:
59
mast Exp $");
#include "interpret.h" #include "svalue.h" #include "multiset.h" #include "mapping.h" #include "array.h" #include "stralloc.h" #include "opcodes.h" #include "operators.h" #include "language.h" #include "pike_memory.h"
pike.git/src/operators.c:561:
#else size=0; for(e=-args; e<0; e++) size+=sp[e].u.integer; sp-=args-1; sp[-1].u.integer=size; #endif /* AUTO_BIGNUM */ break; case BIT_FLOAT: {
-
FLOAT_TYPE sum;
+
FLOAT_
ARG_
TYPE sum;
sum=0.0; for(e=-args; e<0; e++) sum+=sp[e].u.float_number; sp-=args-1; sp[-1].u.float_number=sum; break; } case BIT_FLOAT|BIT_INT: {
-
FLOAT_TYPE sum;
+
FLOAT_
ARG_
TYPE sum;
sum=0.0; for(e=-args; e<0; e++) { if(sp[e].type==T_FLOAT) { sum+=sp[e].u.float_number; }else{
-
sum+=(FLOAT_TYPE)sp[e].u.integer;
+
sum+=(FLOAT_
ARG_
TYPE)sp[e].u.integer;
} } sp-=args-1; sp[-1].type=T_FLOAT; sp[-1].u.float_number=sum; break; } #define ADD_WITH_UNDEFINED(TYPE, T_TYPEID, ADD_FUNC, PUSH_FUNC) do { \ int e; \
pike.git/src/operators.c:2359:
return; case TWO_TYPES(T_FLOAT,T_INT): sp--; sp[-1].u.float_number *= (FLOAT_TYPE)sp[0].u.integer; return; case TWO_TYPES(T_INT,T_FLOAT): sp--; sp[-1].u.float_number=
-
(FLOAT_TYPE) sp[-1].u.integer *
(FLOAT_TYPE)
sp[0].u.float_number;
+
(FLOAT_TYPE) sp[-1].u.integer * sp[0].u.float_number;
sp[-1].type=T_FLOAT; return; case TWO_TYPES(T_INT,T_INT): #ifdef AUTO_BIGNUM if(INT_TYPE_MUL_OVERFLOW(sp[-2].u.integer, sp[-1].u.integer)) { convert_stack_top_to_bignum(); goto do_lfun_multiply; }
pike.git/src/operators.c:2531:
a->type_field=BIT_STRING; pop_n_elems(2); push_array(a); return; } case TWO_TYPES(T_STRING,T_FLOAT): { struct array *a; ptrdiff_t size, pos, last, e;
-
double
len;
+
FLOAT_ARG_TYPE
len;
len=sp[-1].u.float_number; if(len==0.0) OP_DIVISION_BY_ZERO_ERROR("`/"); if(len<0) { len=-len; size=(ptrdiff_t)ceil( ((double)sp[-2].u.string->len) / len); a=allocate_array(size);
pike.git/src/operators.c:2586:
a->type_field=BIT_STRING; pop_n_elems(2); push_array(a); return; } case TWO_TYPES(T_ARRAY, T_INT): { struct array *a;
-
ptrdiff_t size,e,
len,
pos;
+
ptrdiff_t size,e,pos;
-
len=sp[-1].u.integer;
+
INT_TYPE
len=sp[-1].u.integer;
if(!len) OP_DIVISION_BY_ZERO_ERROR("`/"); if(len<0) { len = -len; pos = sp[-2].u.array->size % len; }else{ pos = 0; }
pike.git/src/operators.c:2620:
a->type_field=BIT_ARRAY; pop_n_elems(2); push_array(a); return; } case TWO_TYPES(T_ARRAY,T_FLOAT): { struct array *a; ptrdiff_t last,pos,e,size;
-
double
len;
+
FLOAT_ARG_TYPE
len;
len=sp[-1].u.float_number; if(len==0.0) OP_DIVISION_BY_ZERO_ERROR("`/"); if(len<0) { len=-len; size = (ptrdiff_t)ceil( ((double)sp[-2].u.array->size) / len); a=allocate_array(size);
pike.git/src/operators.c:2732:
/* 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--; sp[-1].u.integer=tmp; return; } default: PIKE_ERROR("`/", "Bad argument 1.\n", sp, 2); }
pike.git/src/operators.c:2863:
switch(TWO_TYPES(sp[-2].type,sp[-1].type)) { case TWO_TYPES(T_STRING,T_INT): { struct pike_string *s=sp[-2].u.string; ptrdiff_t tmp,base; if(!sp[-1].u.integer) OP_MODULO_BY_ZERO_ERROR("`%");
-
tmp=
sp[-1].u.integer
;
-
if(tmp
<0)
+
if(
sp[-1].u.integer<0)
{
-
tmp=s->len % -
tmp
;
+
tmp=s->len % -
sp[-1].u.integer
;
base=0; }else{
-
tmp=s->len %
tmp
;
+
tmp=s->len %
sp[-1].u.integer
;
base=s->len - tmp; } s=string_slice(s, base, tmp); pop_n_elems(2); push_string(s); return; } case TWO_TYPES(T_ARRAY,T_INT): { struct array *a=sp[-2].u.array;
-
INT32
tmp,base;
+
ptrdiff_t
tmp,base;
if(!sp[-1].u.integer) OP_MODULO_BY_ZERO_ERROR("`%");
-
tmp=
sp[-1].u.integer
;
-
if(tmp
<0)
+
if(
sp[-1].u.integer<0)
{
-
tmp=a->size % -
tmp
;
+
tmp=a->size % -
sp[-1].u.integer
;
base=0; }else{
-
tmp=a->size %
tmp
;
+
tmp=a->size %
sp[-1].u.integer
;
base=a->size - tmp; } a=slice_array(a,base,base+tmp); pop_n_elems(2); push_array(a); return; } }