Skip to content

Fix database double type precision bug #709

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
Oct 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion app/src/variant_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ static bool VariantToJson(const Variant& variant, bool prettyPrint,
break;
}
case Variant::kTypeDouble: {
*ss << variant.double_value();
// IEEE 754 double-precision binary floating-point format: binary64 — The
// 53-bit significand precision gives from 15 to 17 significant decimal
// digits Default 32-bit only keeps 7 digit precision
*ss << std::setprecision(17) << variant.double_value();
break;
}
case Variant::kTypeBool: {
Expand Down
8 changes: 8 additions & 0 deletions database/integration_test/src/integration_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ static const int kSimpleInt = 2;
static const int kSimplePriority = 100;
static const double kSimpleDouble = 3.4;
static const bool kSimpleBool = true;
static const double kLongDouble = 0.123456789876543;

TEST_F(FirebaseDatabaseTest, TestSetAndGetSimpleValues) {
const char* test_name = test_info_->name();
Expand All @@ -415,12 +416,15 @@ TEST_F(FirebaseDatabaseTest, TestSetAndGetSimpleValues) {
ref.Child(test_name)
.Child("IntAndPriority")
.SetValueAndPriority(kSimpleInt, kSimplePriority);
firebase::Future<void> f7 =
ref.Child(test_name).Child("LongDouble").SetValue(kLongDouble);
WaitForCompletion(f1, "SetSimpleString");
WaitForCompletion(f2, "SetSimpleInt");
WaitForCompletion(f3, "SetSimpleDouble");
WaitForCompletion(f4, "SetSimpleBool");
WaitForCompletion(f5, "SetSimpleTimestamp");
WaitForCompletion(f6, "SetSimpleIntAndPriority");
WaitForCompletion(f7, "SetLongDouble");
}

// Get the values that we just set, and confirm that they match what we
Expand All @@ -439,12 +443,15 @@ TEST_F(FirebaseDatabaseTest, TestSetAndGetSimpleValues) {
ref.Child(test_name).Child("Timestamp").GetValue();
firebase::Future<firebase::database::DataSnapshot> f6 =
ref.Child(test_name).Child("IntAndPriority").GetValue();
firebase::Future<firebase::database::DataSnapshot> f7 =
ref.Child(test_name).Child("LongDouble").GetValue();
WaitForCompletion(f1, "GetSimpleString");
WaitForCompletion(f2, "GetSimpleInt");
WaitForCompletion(f3, "GetSimpleDouble");
WaitForCompletion(f4, "GetSimpleBool");
WaitForCompletion(f5, "GetSimpleTimestamp");
WaitForCompletion(f6, "GetSimpleIntAndPriority");
WaitForCompletion(f7, "GetLongDouble");

// Get the current time to compare to the Timestamp.
int64_t current_time_milliseconds =
Expand All @@ -458,6 +465,7 @@ TEST_F(FirebaseDatabaseTest, TestSetAndGetSimpleValues) {
TimestampIsNear(current_time_milliseconds));
EXPECT_EQ(f6.result()->value().AsInt64(), kSimpleInt);
EXPECT_EQ(f6.result()->priority().AsInt64(), kSimplePriority);
EXPECT_EQ(f7.result()->value().AsDouble(), kLongDouble);
}
}

Expand Down
4 changes: 4 additions & 0 deletions release_build_files/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,10 @@ workflow use only during the development of your app, not for publicly shipping
code.

## Release Notes
### Next Release
- Changes
- General: Variant double type now support 64-bit while saving to json.
([#1133](https://github.com/firebase/quickstart-unity/issues/1133)).

### 8.6.0
- Changes
Expand Down