|
Packit Service |
310c69 |
/*
|
|
Packit Service |
310c69 |
* Copyright (c) 2020 Red Hat, Inc.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* This program is free software; you can redistribute it and/or
|
|
Packit Service |
310c69 |
* modify it under the terms of the GNU General Public License
|
|
Packit Service |
310c69 |
* as published by the Free Software Foundation; either version 2
|
|
Packit Service |
310c69 |
* of the License, or (at your option) any later version.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* This program is distributed in the hope that it will be useful,
|
|
Packit Service |
310c69 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
310c69 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit Service |
310c69 |
* GNU General Public License for more details.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* You should have received a copy of the GNU General Public License
|
|
Packit Service |
310c69 |
* along with this program; if not, write to the Free Software
|
|
Packit Service |
310c69 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
Packit Service |
310c69 |
* 02110-1301, USA.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* $Id: //eng/uds-releases/jasper/src/uds/numeric.c#2 $
|
|
Packit Service |
310c69 |
*/
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
#include "numeric.h"
|
|
Packit Service |
310c69 |
#include "permassert.h"
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
#define STATIC_ASSERT_ALIGNOF(type, expectedAlignment) \
|
|
Packit Service |
310c69 |
STATIC_ASSERT(__alignof__(type) == (expectedAlignment))
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**********************************************************************/
|
|
Packit Service |
310c69 |
bool multiplyWouldOverflow(uint64_t a, uint64_t b)
|
|
Packit Service |
310c69 |
{
|
|
Packit Service |
310c69 |
return b != 0 && a > UINT64_MAX / b;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**********************************************************************/
|
|
Packit Service |
310c69 |
void numericCompileTimeAssertions(void)
|
|
Packit Service |
310c69 |
{
|
|
Packit Service |
310c69 |
STATIC_ASSERT_SIZEOF(uint64_t, 8);
|
|
Packit Service |
310c69 |
STATIC_ASSERT_SIZEOF(uint32_t, 4);
|
|
Packit Service |
310c69 |
STATIC_ASSERT_SIZEOF(uint16_t, 2);
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
STATIC_ASSERT_SIZEOF(UNALIGNED_WRAPPER(uint64_t), 8);
|
|
Packit Service |
310c69 |
STATIC_ASSERT_SIZEOF(UNALIGNED_WRAPPER(uint32_t), 4);
|
|
Packit Service |
310c69 |
STATIC_ASSERT_SIZEOF(UNALIGNED_WRAPPER(uint16_t), 2);
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
STATIC_ASSERT_ALIGNOF(UNALIGNED_WRAPPER(uint64_t), 1);
|
|
Packit Service |
310c69 |
STATIC_ASSERT_ALIGNOF(UNALIGNED_WRAPPER(uint32_t), 1);
|
|
Packit Service |
310c69 |
STATIC_ASSERT_ALIGNOF(UNALIGNED_WRAPPER(uint16_t), 1);
|
|
Packit Service |
310c69 |
}
|