Skip to content

Commit

Permalink
Restore Variant float to 64-bit
Browse files Browse the repository at this point in the history
  • Loading branch information
fwsGonzo committed Aug 25, 2024
1 parent e485b03 commit 908f764
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
10 changes: 5 additions & 5 deletions program/cpp/api/variant.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,9 @@ struct Variant
private:
Type m_type = NIL;
union {
int64_t i = 0;
bool b;
float f;
int64_t i = 0;
bool b;
double f;
Vector2 v2;
Vector2i v2i;
Vector3 v3;
Expand Down Expand Up @@ -332,7 +332,7 @@ inline Variant::operator uint8_t() const
inline Variant::operator double() const
{
if (m_type == FLOAT)
return static_cast<double>(v.f);
return v.f;
if (m_type == INT)
return static_cast<double>(v.i);
api_throw("std::bad_cast", "Failed to cast Variant to double", this);
Expand All @@ -341,7 +341,7 @@ inline Variant::operator double() const
inline Variant::operator float() const
{
if (m_type == FLOAT)
return v.f;
return static_cast<float>(v.f);
if (m_type == INT)
return static_cast<float>(v.i);
api_throw("std::bad_cast", "Failed to cast Variant to float", this);
Expand Down
6 changes: 3 additions & 3 deletions program/rust/src/godot/variant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ pub struct Vector4i {
pub union VariantUnion {
pub b: bool,
pub i: i64,
pub f: f32,
pub f: f64,
pub v2: Vector2,
pub v2i: Vector2i,
pub v3: Vector3,
Expand Down Expand Up @@ -121,7 +121,7 @@ impl Variant
let v = Variant { t: VariantType::Integer, u: VariantUnion { i: i } };
return v;
}
pub fn new_float(f: f32) -> Variant
pub fn new_float(f: f64) -> Variant
{
let v = Variant { t: VariantType::Float, u: VariantUnion { f: f } };
return v;
Expand Down Expand Up @@ -194,7 +194,7 @@ impl Variant
}
}

pub fn to_float(&self) -> f32
pub fn to_float(&self) -> f64
{
match self.t {
VariantType::Float => {
Expand Down
2 changes: 1 addition & 1 deletion src/sandbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ struct GuestVariant {
union alignas(8) {
int64_t i = 0;
bool b;
float f;
double f;
gaddr_t s; // String & PackedByteArray & Node2D -> GuestStdString
gaddr_t vf32; // PackedFloat32Array -> GuestStdVector<float>
gaddr_t vf64; // PackedFloat64Array -> GuestStdVector<double>
Expand Down

0 comments on commit 908f764

Please sign in to comment.