~ubuntu-branches/ubuntu/trusty/lifelines/trusty

« back to all changes in this revision

Viewing changes to src/interp/pvalmath.c

  • Committer: Bazaar Package Importer
  • Author(s): Felipe Augusto van de Wiel (faw)
  • Date: 2007-05-23 23:49:53 UTC
  • mfrom: (3.1.3 edgy)
  • Revision ID: james.westby@ubuntu.com-20070523234953-ogno9rnbmth61i7p
Tags: 3.0.50-2etch1
* Changing docs/ll-reportmanual.xml and docs/ll-userguide.xml to fix
  documentation build problems (Closes: #418347).

* lifelines-reports
  - Adding a dependency to lifelines >= 3.0.50 to prevent file conflict.
    (Closes: #405500).

* Updating French translation. Thanks to Bernard Adrian. (Closes: #356671).

Show diffs side-by-side

added added

removed removed

Lines of Context:
98
98
        num_conform_pvalues("add", val1, val2, eflg, zerr);
99
99
        if (*eflg) return;
100
100
        switch (ptype(val1)) {
101
 
        case PINT:   *pvalue_to_pint(val1) += pvalue_to_int(val2); break;
102
 
        case PFLOAT: *pvalue_to_pfloat(val1) += pvalue_to_float(val2); break;
 
101
        case PINT:
 
102
                set_pvalue_int(val1, pvalue_to_int(val1) +  pvalue_to_int(val2));
 
103
                break;
 
104
        case PFLOAT:
 
105
                set_pvalue_float(val1, pvalue_to_float(val1) + pvalue_to_float(val2));
 
106
                break;
103
107
        default: invalid_numeric_type("add", val1, eflg, zerr); return;
104
108
        }
105
109
        delete_pvalue(val2);
114
118
        num_conform_pvalues("sub", val1, val2, eflg, zerr);
115
119
        if (*eflg) return;
116
120
        switch (ptype(val1)) {
117
 
        case PINT:   *pvalue_to_pint(val1) -= pvalue_to_int(val2); break;
118
 
        case PFLOAT: *pvalue_to_pfloat(val1) -= pvalue_to_float(val2); break;
 
121
        case PINT:
 
122
                set_pvalue_int(val1, pvalue_to_int(val1) - pvalue_to_int(val2));
 
123
                break;
 
124
        case PFLOAT:
 
125
                set_pvalue_float(val1, pvalue_to_float(val1) - pvalue_to_float(val2));
 
126
                break;
119
127
        default: invalid_numeric_type("sub", val1, eflg, zerr); return;
120
128
        }
121
129
        delete_pvalue(val2);
130
138
        num_conform_pvalues("mul", val1, val2, eflg, zerr);
131
139
        if (*eflg) return;
132
140
        switch (ptype(val1)) {
133
 
        case PINT:   *pvalue_to_pint(val1) *= pvalue_to_int(val2); break;
134
 
        case PFLOAT: *pvalue_to_pfloat(val1) *= pvalue_to_float(val2); break;
 
141
        case PINT:
 
142
                set_pvalue_int(val1, pvalue_to_int(val1) * pvalue_to_int(val2));
 
143
                break;
 
144
        case PFLOAT:
 
145
                set_pvalue_float(val1, pvalue_to_float(val1) * pvalue_to_float(val2));
 
146
                break;
135
147
        default: invalid_numeric_type("mul", val1, eflg, zerr); return;
136
148
        }
137
149
        delete_pvalue(val2);
145
157
        if (*eflg) return;
146
158
        num_conform_pvalues("div", val1, val2, eflg, zerr);
147
159
        if (*eflg) return;
148
 
        if (is_zero(val2)) { illegal_value("div", val2, eflg, zerr); return; }
 
160
        if (is_numeric_zero(val2)) { illegal_value("div", val2, eflg, zerr); return; }
149
161
        switch (ptype(val1)) {
150
 
        case PINT:   *pvalue_to_pint(val1) /= pvalue_to_int(val2); break;
151
 
        case PFLOAT: *pvalue_to_pfloat(val1) /= pvalue_to_float(val2); break;
 
162
        case PINT: 
 
163
                set_pvalue_int(val1, pvalue_to_int(val1) / pvalue_to_int(val2));
 
164
                break;
 
165
        case PFLOAT:
 
166
                set_pvalue_float(val1, pvalue_to_float(val1) / pvalue_to_float(val2));
 
167
                break;
152
168
        default: invalid_numeric_type("div", val1, eflg, zerr); return;
153
169
        }
154
170
        delete_pvalue(val2);
162
178
        if (*eflg) return;
163
179
        num_conform_pvalues("mod", val1, val2, eflg, zerr);
164
180
        if (*eflg) return;
165
 
        if (is_zero(val2)) { illegal_value("mod", val2, eflg, zerr); return; }
 
181
        if (is_numeric_zero(val2)) { illegal_value("mod", val2, eflg, zerr); return; }
166
182
        switch (ptype(val1)) {
167
183
        case PINT:
168
184
                {
169
185
                        INT i1 = pvalue_to_int(val1) % pvalue_to_int(val2);
170
 
                        *pvalue_to_pint(val1) = i1;
 
186
                        set_pvalue_int(val1, i1);
171
187
                }
172
188
                break;
173
189
        default: invalid_numeric_type("mod", val1, eflg, zerr); return;
216
232
        case PINT:
217
233
                rel = (pvalue_to_int(val1) >= pvalue_to_int(val2)); 
218
234
                break;
219
 
        default: invalid_numeric_type("mod", val1, eflg, zerr); return;
 
235
        default: invalid_numeric_type("ge", val1, eflg, zerr); return;
220
236
        }
221
237
        set_pvalue_bool(val1, rel);
222
238
        delete_pvalue(val2);
239
255
        case PINT: 
240
256
                rel = (pvalue_to_int(val1) < pvalue_to_int(val2)); 
241
257
                break;
242
 
        default: invalid_numeric_type("mod", val1, eflg, zerr); return;
 
258
        default: invalid_numeric_type("lt", val1, eflg, zerr); return;
243
259
        }
244
260
        set_pvalue_bool(val1, rel);
245
261
        delete_pvalue(val2);
262
278
        case PINT:
263
279
                rel = pvalue_to_int(val1) > pvalue_to_int(val2);
264
280
                break;
265
 
        default: invalid_numeric_type("mod", val1, eflg, zerr); return;
 
281
        default: invalid_numeric_type("gt", val1, eflg, zerr); return;
266
282
        }
267
283
        set_pvalue_bool(val1, rel);
268
284
        delete_pvalue(val2);
286
302
                        INT xi = 1, xe = pvalue_to_int(val1);
287
303
                        for (i = 1; i <= n; i++)
288
304
                                xi *= xe;
289
 
                        *pvalue_to_pint(val1) = xi;
 
305
                        set_pvalue_int(val1, xi);
290
306
                }
291
307
                break;
292
308
        case PFLOAT:
294
310
                        float xf=1, xe = pvalue_to_float(val1);
295
311
                        for (i = 1; i <= n; i++)
296
312
                                xf *= xe;
297
 
                        *pvalue_to_pfloat(val1) = xf;
 
313
                        set_pvalue_float(val1, xf);
298
314
                }
299
315
                break;
300
316
        default: invalid_numeric_type("exp", val1, eflg, zerr); return;
309
325
{
310
326
        if (*eflg) return;
311
327
        switch (ptype(val)) {
312
 
        case PINT:   *pvalue_to_pint(val) += 1; break;
313
 
        case PFLOAT: *pvalue_to_pfloat(val) += 1.; break;
 
328
        case PINT:
 
329
                set_pvalue_int(val, pvalue_to_int(val) + 1);
 
330
                break;
 
331
        case PFLOAT:
 
332
                set_pvalue_float(val, pvalue_to_float(val) + 1.0);
 
333
                break;
314
334
        default: invalid_numeric_type("incr", val, eflg, zerr); return;
315
335
        }
316
336
        return;
323
343
{
324
344
        if (*eflg) return;
325
345
        switch (ptype(val)) {
326
 
        case PINT:   *pvalue_to_pint(val) -= 1; break;
327
 
        case PFLOAT: *pvalue_to_pfloat(val) -= 1.; break;
 
346
        case PINT:
 
347
                set_pvalue_int(val, pvalue_to_int(val) - 1);
 
348
                break;
 
349
        case PFLOAT:
 
350
                set_pvalue_float(val, pvalue_to_float(val) - 1.0);
 
351
                break;
328
352
        default: invalid_numeric_type("decr", val, eflg, zerr); return;
329
353
        }
330
354
}
336
360
{
337
361
        if (*eflg) return;
338
362
        switch (ptype(val)) {
339
 
        case PINT:   *pvalue_to_pint(val) = -pvalue_to_int(val); break;
340
 
        case PFLOAT: *pvalue_to_pfloat(val) = -pvalue_to_float(val); break;
 
363
        case PINT:
 
364
                set_pvalue_int(val, -pvalue_to_int(val));
 
365
                break;
 
366
        case PFLOAT:
 
367
                set_pvalue_float(val, -pvalue_to_float(val));
 
368
                break;
341
369
        default: invalid_numeric_type("neg", val, eflg, zerr); return;
342
370
        }
343
371
        return;
344
372
}
345
373
/*=================================
346
 
 * is_zero -- See if PVALUE is zero
 
374
 * is_numeric_zero -- See if numeric PVALUE is zero
347
375
 *===============================*/
348
376
BOOLEAN
349
 
is_zero (PVALUE val)
 
377
is_numeric_zero (PVALUE val)
350
378
{
351
379
        switch (ptype(val)) {
352
380
        case PINT: return pvalue_to_int(val) == 0;
353
381
        case PFLOAT: return pvalue_to_float(val) == 0.;
354
 
        case PANY: return pvalue(val) == NULL;
355
 
        default: return TRUE;
 
382
        case PNULL: return TRUE;
356
383
        }
 
384
        ASSERT(0); /* No other numeric types */
 
385
        return FALSE;
357
386
}
358
387
/*============================================================
359
388
 * num_conform_pvalues -- Make the types of two values conform
363
392
{
364
393
        ASSERT(val1 && val2);
365
394
 
366
 
        if (ptype(val1) == PANY && pvalue(val1) == NULL)
 
395
        if (ptype(val1) == PNULL)
367
396
                ptype(val1) = ptype(val2);
368
 
        if (ptype(val2) == PANY && pvalue(val2) == NULL)
 
397
        if (ptype(val2) == PNULL)
369
398
                ptype(val2) = ptype(val1);
370
 
        if (ptype(val1) == PANY && ptype(val2) == PANY)
 
399
        if (ptype(val1) == PNULL && ptype(val2) == PNULL)
371
400
                ptype(val1) = ptype(val2) = PINT;
372
401
        if (is_numeric_pvalue(val1) && is_numeric_pvalue(val2)) {
373
402
                INT hitype = max(ptype(val1), ptype(val2));
378
407
        if (zerr) {
379
408
                ZSTR zt1 = describe_pvalue(val1), zt2 = describe_pvalue(val2);
380
409
                ASSERT(!(*zerr));
381
 
                (*zerr) = zs_newf(_("%s: incompatible types: %s and %s")
 
410
                (*zerr) = zs_newf(_("%s: not compatible numeric types: %s and %s")
382
411
                        , op, zs_str(zt1), zs_str(zt2));
383
412
                zs_free(&zt1);
384
413
                zs_free(&zt2);