File: evalvar.c

package info (click to toggle)
wcalc 2.2.2-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 2,228 kB
  • ctags: 698
  • sloc: ansic: 6,918; objc: 1,835; sh: 766; yacc: 644; lex: 573; makefile: 78
file content (32 lines) | stat: -rw-r--r-- 644 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <gmp.h>
#include <mpfr.h>
#include "variables.h"
#include "calculator.h"
#include "number_formatting.h"
#ifdef MEMWATCH
#include "memwatch.h"
#endif

char *evalvar(char *varname)
{
    struct answer a;
    char *varvalue, junk;
    mpfr_t f;

    a = getvar_full(varname);
    if (!a.err) {
	mpfr_init(f);
	if (a.exp) {		       // it is an expression
	    parseme(a.exp);
	    mpfr_set(f, last_answer, GMP_RNDN);
	} else {		       // it is a value
	    mpfr_set(f, a.val, GMP_RNDN);
	    mpfr_clear(a.val);
	}
	varvalue = num_to_str_complex(f, 10, 0, -1, 1, &junk);
	mpfr_clear(f);
	return varvalue;
    } else {
	return NULL;
    }
}