pike.git / src / operators.c

version» Context lines:

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.250 2009/07/12 19:43:05 grubba Exp $ + || $Id: operators.c,v 1.251 2009/08/05 09:43:19 mast Exp $   */      #include "global.h"   #include <math.h>   #include "interpret.h"   #include "svalue.h"   #include "multiset.h"   #include "mapping.h"   #include "array.h"   #include "stralloc.h"
pike.git/src/operators.c:46:    * /grubba 2008-07-08    */   #undef PIKE_MERGE_DESTR_A   #define PIKE_MERGE_DESTR_A 0       /* These calculations should always give some margin based on the size. */    /* The calculations utilize that log10(256) ~= 2.4 < 5/2. */       /* One extra char for the sign. */   #define MAX_INT_SPRINTF_LEN (1 + (SIZEOF_INT_TYPE * 5 + 1) / 2) -  /* Three quarters of the float is the mantissa. */ - #define MAX_FLOAT_PREC_LEN ((SIZEOF_FLOAT_TYPE * 15 + 4) / 8) +     /* One quarter of the float is the exponent. */   #define MAX_FLOAT_EXP_LEN ((SIZEOF_FLOAT_TYPE * 5 + 4) / 8)    /* Six extra chars: Mantissa sign, decimal point, zero before the -  * decimal point, the 'e', exponent sign, and an extra digit due +  * decimal point, the 'e' exponent sign, and an extra digit due    * to the mantissa/exponent split. */ - #define MAX_FLOAT_SPRINTF_LEN (6 + MAX_FLOAT_PREC_LEN + MAX_FLOAT_EXP_LEN) + #define MAX_FLOAT_SPRINTF_LEN (6 + PIKEFLOAT_DIG + MAX_FLOAT_EXP_LEN)       /* Enough to hold a Pike float or int in textform including a trailing \0    */   #define MAX_NUM_BUF (MAXIMUM(MAX_INT_SPRINTF_LEN,MAX_FLOAT_SPRINTF_LEN)+1)      void index_no_free(struct svalue *to,struct svalue *what,struct svalue *ind)   {   #ifdef PIKE_SECURITY    if(what->type <= MAX_COMPLEX)    if(!CHECK_DATA_SECURITY(what->u.array, SECURITY_BIT_INDEX))
pike.git/src/operators.c:479:    return;       default:    Pike_error("Cannot cast %s to string.\n", get_name_of_type(sp[-1].type));       case PIKE_T_STRING:    return;       case T_FLOAT:    sprintf(buf,"%.*"PRINTPIKEFLOAT"g", -  MAX_FLOAT_PREC_LEN, sp[-1].u.float_number); +  PIKEFLOAT_DIG, sp[-1].u.float_number);    /* Ensure that either an exponent or a decimal point gets printed,    * since %g can remove both which would make it look like an integer. */    if (!strchr (buf, '.') && !strchr (buf, 'e'))    strcat (buf, ".0");    break;       case T_INT:    sprintf(buf, "%"PRINTPIKEINT"d", sp[-1].u.integer);    break;    }
pike.git/src/operators.c:1621: Inside #if defined(PIKE_DEBUG)
  #ifdef PIKE_DEBUG    if (strlen (buffer) > MAX_INT_SPRINTF_LEN)    Pike_fatal ("Formatted integer %s is %"PRINTSIZET"u, "    "longer than assumed max %"PRINTSIZET"u.\n",    buffer, strlen (buffer), MAX_INT_SPRINTF_LEN);   #endif    goto append_buffer;       case T_FLOAT:    sprintf(buffer,"%.*"PRINTPIKEFLOAT"g", -  MAX_FLOAT_PREC_LEN, sp[e].u.float_number); +  PIKEFLOAT_DIG, sp[e].u.float_number);    /* See comment for T_FLOAT in o_cast_to_string. */    if (!strchr (buffer, '.') && !strchr (buffer, 'e'))    strcat (buffer, ".0");   #ifdef PIKE_DEBUG    if (strlen (buffer) > MAX_FLOAT_SPRINTF_LEN)    Pike_fatal ("Formatted float %s is %"PRINTSIZET"u, "    "longer than assumed max %"PRINTSIZET"u.\n",    buffer, strlen (buffer), MAX_FLOAT_SPRINTF_LEN);   #endif