Skip to content

Commit

Permalink
DIRECTOR: Lingo: FLOAT actually has to have double precision. Switching.
Browse files Browse the repository at this point in the history
  • Loading branch information
sev- committed Aug 3, 2016
1 parent 0b64438 commit 996b909
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 20 deletions.
10 changes: 5 additions & 5 deletions engines/director/lingo/lingo-builtins.cpp
Expand Up @@ -73,7 +73,7 @@ void Lingo::b_abs() {
void Lingo::b_atan() {
Datum d = g_lingo->pop();
d.toFloat();
d.u.f = atanf(d.u.f);
d.u.f = atan(d.u.f);
g_lingo->push(d);
}

Expand All @@ -88,7 +88,7 @@ void Lingo::b_exp() {
Datum d = g_lingo->pop();
d.toInt(); // Lingo uses int, so we're enforcing it
d.toFloat();
d.u.f = expf(d.u.f);
d.u.f = exp(d.u.f);
g_lingo->push(d);
}

Expand All @@ -107,14 +107,14 @@ void Lingo::b_integer() {
void Lingo::b_log() {
Datum d = g_lingo->pop();
d.toFloat();
d.u.f = logf(d.u.f);
d.u.f = log(d.u.f);
g_lingo->push(d);
}

void Lingo::b_pi() {
Datum d;
d.toFloat();
d.u.f = 3.14159265358;
d.u.f = 3.14159265358979;
g_lingo->push(d);
}

Expand All @@ -123,7 +123,7 @@ void Lingo::b_power() {
Datum d2 = g_lingo->pop();
d1.toFloat();
d2.toFloat();
d1.u.f = powf(d2.u.f, d1.u.f);
d1.u.f = pow(d2.u.f, d1.u.f);
g_lingo->push(d1);
}

Expand Down
4 changes: 2 additions & 2 deletions engines/director/lingo/lingo-code.cpp
Expand Up @@ -111,10 +111,10 @@ void Lingo::c_constpush() {
void Lingo::c_fconstpush() {
Datum d;
inst i = (*g_lingo->_currentScript)[g_lingo->_pc];
d.u.f = *((float *)&i);
d.u.f = *((double *)&i);
d.type = FLOAT;

g_lingo->_pc += g_lingo->calcCodeAlignment(sizeof(float));
g_lingo->_pc += g_lingo->calcCodeAlignment(sizeof(double));

g_lingo->push(d);
}
Expand Down
6 changes: 3 additions & 3 deletions engines/director/lingo/lingo-codegen.cpp
Expand Up @@ -164,8 +164,8 @@ int Lingo::codeString(const char *str) {
return _currentScript->size();
}

int Lingo::codeFloat(float f) {
int numInsts = calcCodeAlignment(sizeof(float));
int Lingo::codeFloat(double f) {
int numInsts = calcCodeAlignment(sizeof(double));

// Where we copy the string over
int pos = _currentScript->size();
Expand All @@ -174,7 +174,7 @@ int Lingo::codeFloat(float f) {
for (int i = 0; i < numInsts; i++)
_currentScript->push_back(0);

float *dst = (float *)((byte *)&_currentScript->front() + pos * sizeof(inst));
double *dst = (double *)((byte *)&_currentScript->front() + pos * sizeof(inst));

*dst = f;

Expand Down
2 changes: 1 addition & 1 deletion engines/director/lingo/lingo-gr.cpp
Expand Up @@ -211,7 +211,7 @@ typedef union YYSTYPE
{
Common::String *s;
int i;
float f;
double f;
int code;
int narg; /* number of arguments */
}
Expand Down
2 changes: 1 addition & 1 deletion engines/director/lingo/lingo-gr.h
Expand Up @@ -148,7 +148,7 @@ typedef union YYSTYPE
{
Common::String *s;
int i;
float f;
double f;
int code;
int narg; /* number of arguments */
}
Expand Down
2 changes: 1 addition & 1 deletion engines/director/lingo/lingo-gr.y
Expand Up @@ -65,7 +65,7 @@ using namespace Director;
%union {
Common::String *s;
int i;
float f;
double f;
int code;
int narg; /* number of arguments */
}
Expand Down
6 changes: 3 additions & 3 deletions engines/director/lingo/lingo.cpp
Expand Up @@ -197,10 +197,10 @@ int Datum::toInt() {
return u.i;
}

float Datum::toFloat() {
double Datum::toFloat() {
switch (type) {
case INT:
u.f = (float)u.i;
u.f = (double)u.i;
type = FLOAT;
break;
case FLOAT:
Expand All @@ -220,7 +220,7 @@ Common::String *Datum::toString() {
s->format("%d", u.i);
break;
case FLOAT:
s->format("%f", u.f);
s->format(g_lingo->_floatPrecisionFormat.c_str(), u.f);
break;
case STRING:
delete s;
Expand Down
8 changes: 4 additions & 4 deletions engines/director/lingo/lingo.h
Expand Up @@ -82,7 +82,7 @@ struct Symbol { /* symbol table entry */
int type;
union {
int i; /* VAR */
float f; /* FLOAT */
double f; /* FLOAT */
ScriptData *defn; /* FUNCTION, PROCEDURE */
Common::String *s; /* STRING */
} u;
Expand All @@ -97,14 +97,14 @@ struct Datum { /* interpreter stack type */

union {
int i;
float f;
double f;
Common::String *s;
Symbol *sym;
} u;

Datum() { u.sym = NULL; type = VOID; }

float toFloat();
double toFloat();
int toInt();
Common::String *toString();

Expand Down Expand Up @@ -173,7 +173,7 @@ class Lingo {
void codeArgStore();
int codeId(Common::String &s);
int codeId_(Common::String &s);
int codeFloat(float f);
int codeFloat(double f);

static void c_xpop();
static void c_printtop();
Expand Down

0 comments on commit 996b909

Please sign in to comment.