VirtualBox

source: vbox/trunk/src/VBox/Runtime/testcase/tstRTMath.cpp@ 75500

Last change on this file since 75500 was 69434, checked in by vboxsync, 7 years ago

Runtime: scm updates

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.8 KB
Line 
1/* $Id: tstRTMath.cpp 69434 2017-10-27 15:48:25Z vboxsync $ */
2/** @file
3 * IPRT Testcase - base mathematics.
4 */
5
6/*
7 * Copyright (C) 2017 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27#include <iprt/test.h>
28
29RT_C_DECLS_BEGIN
30extern uint64_t __udivmoddi4(uint64_t u64A, uint64_t u64B, uint64_t *pu64R);
31RT_C_DECLS_END
32
33static struct {
34 uint64_t u64A;
35 uint64_t u64B;
36 uint64_t u64Div;
37 uint64_t u64Rem;
38} gUDivMod[]
39=
40{
41 { 10, 5, 2, 0 },
42 { (uint64_t)-10, (uint64_t)-5, 0, (uint64_t)-10 },
43 { UINT64_C(0x7FFFFFFFFFFFFFFF), 1, UINT64_C(0x7FFFFFFFFFFFFFFF), 0 },
44 { UINT64_C(0x7FFFFFFFFFFFFFFF), UINT64_C(0x7FFFFFFFFFFFFFFF), 1, 0 },
45 { UINT64_C(0xFFFFFFFFFFFFFFFF), 2, UINT64_C(0x7FFFFFFFFFFFFFFF), 1 },
46 { 1, 2, 0, 1 },
47 { UINT64_C(0xFFFFFFFFFFFFFFFE), UINT64_C(0xFFFFFFFFFFFFFFFF), 0, UINT64_C(0xFFFFFFFFFFFFFFFE) },
48 { UINT64_C(0xEEEEEEEE12345678), UINT64_C(0x00000000EEEEEEEE), 0x100000000, 0x12345678 },
49};
50
51static void tstCorrectness(RTTEST hTest)
52{
53 RTTestSub(hTest, "Correctness");
54
55 uint64_t u64Rem;
56 for (unsigned i = 0; i < RT_ELEMENTS(gUDivMod); i++)
57 RTTEST_CHECK(hTest, __udivmoddi4(gUDivMod[i].u64A, gUDivMod[i].u64B, &u64Rem) == gUDivMod[i].u64Div && u64Rem == gUDivMod[i].u64Rem);
58}
59
60int main()
61{
62 RTTEST hTest;
63 int rc = RTTestInitAndCreate("tstRTMath", &hTest);
64 if (rc)
65 return rc;
66 RTTestBanner(hTest);
67
68 tstCorrectness(hTest);
69
70 return RTTestSummaryAndDestroy(hTest);
71}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette