Skip to content

Commit

Permalink
More double-correctness changes
Browse files Browse the repository at this point in the history
  • Loading branch information
SaladDais committed Mar 14, 2024
1 parent 6a08183 commit 25b8ade
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion libtailslide/lslmini.hh
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ class LSLIntegerConstant : public LSLConstant {

class LSLFloatConstant : public LSLConstant {
public:
LSLFloatConstant( ScriptContext *ctx, float v ) : LSLConstant(ctx), _mValue(v) { _mType = TYPE(LST_FLOATINGPOINT); }
LSLFloatConstant( ScriptContext *ctx, double v ) : LSLConstant(ctx), _mValue(v) { _mType = TYPE(LST_FLOATINGPOINT); }

virtual std::string getNodeName() {
char buf[256];
Expand Down
5 changes: 3 additions & 2 deletions libtailslide/operations.cc
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ LSLConstant *TailslideOperationBehavior::operation(
// Float Constants
LSLConstant *TailslideOperationBehavior::operation(
LSLOperator operation, LSLFloatConstant *cv, LSLConstant *other_const) {
float value = cv->getValue();
double value = cv->getValue();
// unary op
if (other_const == nullptr) {
if (operation == '-')
Expand Down Expand Up @@ -422,7 +422,8 @@ LSLConstant *TailslideOperationBehavior::operation(
return _mAllocator->newTracked<LSLVectorConstant>(nv[0], nv[1], nv[2]);
}
case NODE_FLOAT_CONSTANT: {
float ov = ((LSLFloatConstant *) other_const)->getValue();
// TODO: are these operations done in double or single space?
float ov = (float)((LSLFloatConstant *) other_const)->getValue();
float nv[3];
switch (operation) {
case '*':
Expand Down
4 changes: 2 additions & 2 deletions libtailslide/passes/mono/script_compiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,10 @@ void MonoScriptCompiler::pushConstant(LSLConstant *cv) {
}

/// used for a number of cases, including pushing float constants and vec/quat components
void MonoScriptCompiler::pushFloatLiteral(float value) {
void MonoScriptCompiler::pushFloatLiteral(double value) {
// pushed as a double for some reason
// use the binary hex form specified in the ECMA standard to preserve precision
auto d_val = (double)value;
auto d_val = value;
auto *b_val = reinterpret_cast<uint8_t *>(&d_val);
// enough room for all of the octets plus null. much less annoying than
// the stringstream form and no C++20 so we don't have std::format
Expand Down
2 changes: 1 addition & 1 deletion libtailslide/passes/mono/script_compiler.hh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class MonoScriptCompiler : public ASTVisitor {
void pushLValueContainer(LSLLValueExpression *lvalue);
void pushLValue(LSLLValueExpression *lvalue);
void pushConstant(LSLConstant *cv);
void pushFloatLiteral(float value);
void pushFloatLiteral(double value);
void storeToLValue(LSLLValueExpression *lvalue, bool push_result);
void castTopOfStack(LSLIType from_type, LSLIType to_type);
std::string getGlobalVarSpecifier(LSLSymbol *sym);
Expand Down
2 changes: 1 addition & 1 deletion libtailslide/passes/pretty_print.cc
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ bool PrettyPrintVisitor::visit(LSLQuaternionExpression *quat_expr) {
return false;
}

static std::string format_float(float v) {
static std::string format_float(double v) {
if (!std::isfinite(v)) {
// this really should never happen, as LSL doesn't have a NaN literal and we should
// refuse to fold constants that result in NaN, but as a last resort try typecasting
Expand Down

0 comments on commit 25b8ade

Please sign in to comment.