From f3b065f03a7b68310b489d5d97b11985ef36e977 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Aulery?= Date: Sun, 7 Jul 2013 02:02:38 +0200 Subject: Use the new M_PI symbol from math.h MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use the new M_PI symbol from math.h and fix and a value of the same accuracy if it's necessary to redefine M_PI. Signed-off-by: Stéphane Aulery Reviewed-by: Alan Coopersmith Signed-off-by: Alan Coopersmith --- math.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/math.c b/math.c index 7f81757..bb31b14 100644 --- a/math.c +++ b/math.c @@ -18,8 +18,8 @@ #include "xcalc.h" -#ifndef PI /* sometimes defined in math.h */ -#define PI 3.14159265358979 +#ifndef M_PI /* sometimes defined in math.h */ +#define M_PI 3.14159265358979323846 #endif #define E 2.71828182845904 #define MAXDISP 11 @@ -42,8 +42,8 @@ jmp_buf env; static int flagINV, flagPAREN, flagM, drgmode; /* display flags */ -static double drg2rad=PI/180.0; /* Conversion factors for trig funcs */ -static double rad2drg=180.0/PI; +static double drg2rad=M_PI/180.0; /* Conversion factors for trig funcs */ +static double rad2drg=180.0/M_PI; static int entered=1; /* true if display contains a valid number. if==2, then use 'dnum', rather than the string stored in the display. (for accuracy) @@ -633,8 +633,8 @@ drgf(void) if (entered==1) parse_double(dispstr,"%lf",&dnum); switch (drgmode) { - case DEG: dnum=dnum*PI/180.0; break; - case RAD: dnum=dnum*200.0/PI; break; + case DEG: dnum=dnum*M_PI/180.0; break; + case RAD: dnum=dnum*200.0/M_PI; break; case GRAD: dnum=dnum*90.0/100.0; break; } entered=2; @@ -646,14 +646,14 @@ drgf(void) flagINV=0; drgmode = (drgmode + 1) % 3; switch (drgmode) { - case DEG: drg2rad=PI / 180.0; - rad2drg=180.0 / PI; + case DEG: drg2rad=M_PI / 180.0; + rad2drg=180.0 / M_PI; break; case RAD: drg2rad=1.0; rad2drg=1.0; break; - case GRAD: drg2rad=PI / 200.0; - rad2drg=200.0 / PI; + case GRAD: drg2rad=M_PI / 200.0; + rad2drg=200.0 / M_PI; break; } DrawDisplay(); @@ -689,7 +689,7 @@ oneop(int keynum) switch (keynum) { /* do the actual math fn. */ case kE: if (rpn && memop != kENTR) PushNum(dnum); dnum=E; break; - case kPI: if (rpn && memop != kENTR) PushNum(dnum); dnum=PI; break; + case kPI: if (rpn && memop != kENTR) PushNum(dnum); dnum=M_PI; break; case kRECIP: dnum=1.0/dnum; break; case kSQR: flagINV = !flagINV; /* fall through to */ case kSQRT: if (flagINV) dnum=dnum*dnum; @@ -908,6 +908,6 @@ ResetCalc(void) strcpy(dispstr,"0"); draw(dispstr); ClearStacks(); - drg2rad=PI/180.0; - rad2drg=180.0/PI; + drg2rad=M_PI/180.0; + rad2drg=180.0/M_PI; } -- cgit v1.2.3