unstarted_runtime: add cutout for Math.floor
Needed in order to make BouncyCastleProvider initializable in
compile time
(cherry picked from commit a8908ef14cf2d2e0d05e41e319da5d6909325ae2)
Bug: 28108158
Change-Id: Id6b4e3d4dde45354562603f41134d8d21da2b423
diff --git a/runtime/interpreter/unstarted_runtime.cc b/runtime/interpreter/unstarted_runtime.cc
index 81be959..a75f878 100644
--- a/runtime/interpreter/unstarted_runtime.cc
+++ b/runtime/interpreter/unstarted_runtime.cc
@@ -495,9 +495,7 @@
}
}
-void UnstartedRuntime::UnstartedMathCeil(
- Thread* self ATTRIBUTE_UNUSED, ShadowFrame* shadow_frame, JValue* result, size_t arg_offset) {
- double in = shadow_frame->GetVRegDouble(arg_offset);
+static double ComputeCeil(double in) {
double out;
// Special cases:
// 1) NaN, infinity, +0, -0 -> out := in. All are guaranteed by cmath.
@@ -507,7 +505,21 @@
} else {
out = ceil(in);
}
- result->SetD(out);
+ return out;
+}
+
+void UnstartedRuntime::UnstartedMathCeil(
+ Thread* self ATTRIBUTE_UNUSED, ShadowFrame* shadow_frame, JValue* result, size_t arg_offset) {
+ double in = shadow_frame->GetVRegDouble(arg_offset);
+ result->SetD(ComputeCeil(in));
+}
+
+void UnstartedRuntime::UnstartedMathFloor(
+ Thread* self ATTRIBUTE_UNUSED, ShadowFrame* shadow_frame, JValue* result, size_t arg_offset) {
+ double in = shadow_frame->GetVRegDouble(arg_offset);
+ // From the JavaDocs:
+ // "Note that the value of Math.ceil(x) is exactly the value of -Math.floor(-x)."
+ result->SetD(-ComputeCeil(-in));
}
void UnstartedRuntime::UnstartedObjectHashCode(