14#include "arcane/utils/ArcanePrecomp.h"
16#include "arcane/utils/Math.h"
17#include "arcane/utils/ArrayView.h"
33 unsigned long long intVal;
34 explicit DoubleInt(
const double x)
40 int digit_to_bits[] = { 0, 0, 0, 0, 0, 0, 0, 0, 41, 31, 26, 21, 16, 12, 11 };
42 inline double _doTruncate(
double x,
unsigned int numDiscardBits)
45 if (numDiscardBits > 0) {
46 unsigned long long halfBit = (1ULL << (numDiscardBits - 1));
47 unsigned long long mantissaDiscardMask = ~(halfBit - 1) ^ 0xfff0000000000000ULL;
48 unsigned long long test = num.intVal & mantissaDiscardMask;
49 num.intVal &= 0xfff0000000000000ULL;
51 if (test == 0x0010000000000000ULL) {
55 num.intVal |= test & ~halfBit;
61 inline double _doTruncateDigit(
double x,
int nb_digit)
69 int nb_bit = digit_to_bits[nb_digit];
72 return _doTruncate(x, nb_bit);
83 return _doTruncateDigit(v, nb_digit);
100 values[i] = (
float)values[i];
105 int nb_bit = digit_to_bits[nb_digit];
108 for (
Integer i = 0; i < n; ++i)
109 values[i] = _doTruncate(values[i], nb_bit);
Modifiable view of an array of type T.
constexpr Integer size() const noexcept
Returns the size of the array.
double truncateDouble(double v, Integer nb_digit)
Truncates the precision of the real number v to nb_digit significant figures.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Int32 Integer
Type representing an integer.