Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: mbed-TFT-example-NCS36510 mbed-Accelerometer-example-NCS36510 mbed-Accelerometer-example-NCS36510
Diff: TESTS/mbedmicro-mbed/div/main.cpp
- Revision:
- 0:098463de4c5d
diff -r 000000000000 -r 098463de4c5d TESTS/mbedmicro-mbed/div/main.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/TESTS/mbedmicro-mbed/div/main.cpp Wed Jan 25 20:34:15 2017 +0000
@@ -0,0 +1,41 @@
+#include <utility> // std::pair
+#include "mbed.h"
+#include "greentea-client/test_env.h"
+
+uint32_t test_64(uint64_t ticks) {
+ ticks >>= 3; // divide by 8
+ if (ticks > 0xFFFFFFFF) {
+ ticks /= 3;
+ } else {
+ ticks = (ticks * 0x55555556) >> 32; // divide by 3
+ }
+ return (uint32_t)(0xFFFFFFFF & ticks);
+}
+
+const char *result_str(bool result) {
+ return result ? "[OK]" : "[FAIL]";
+}
+
+int main() {
+ GREENTEA_SETUP(5, "default_auto");
+
+ bool result = true;
+
+ { // 0xFFFFFFFF * 8 = 0x7fffffff8
+ std::pair<uint32_t, uint64_t> values = std::make_pair(0x55555555, 0x7FFFFFFF8);
+ uint32_t test_ret = test_64(values.second);
+ bool test_res = values.first == test_ret;
+ result = result && test_res;
+ printf("64bit: 0x7FFFFFFF8: expected 0x%lX got 0x%lX ... %s\r\n", values.first, test_ret, result_str(test_res));
+ }
+
+ { // 0xFFFFFFFF * 24 = 0x17ffffffe8
+ std::pair<uint32_t, uint64_t> values = std::make_pair(0xFFFFFFFF, 0x17FFFFFFE8);
+ uint32_t test_ret = test_64(values.second);
+ bool test_res = values.first == test_ret;
+ result = result && test_res;
+ printf("64bit: 0x17FFFFFFE8: expected 0x%lX got 0x%lX ... %s\r\n", values.first, test_ret, result_str(test_res));
+ }
+
+ GREENTEA_TESTSUITE_RESULT(result);
+}