Commit e605a14e authored by Andreas Haas's avatar Andreas Haas Committed by Commit Bot

Add a not-NaN DCHECK to the Float32 constructor

The class Float32 stores the bit pattern of a float as uint32_t to
guarantee that the exact bit pattern of the contained value is
preserved. This is necessary because the bit pattern of a NaN may
change, e.g. when it is passed as a parameter.

For convenience the Float32 class provides a constructor with a float
parameter. Since this constructor cannot guarantee that the right bit
pattern will be stored for NaNs, this CL adds a DCHECK now to make
sure that the constructor is never used with a NaN.

R=mstarzinger@chromium.org

Change-Id: Iba85a5a1bb2778d5f8bdc1aad97524ef8369b73d
Reviewed-on: https://chromium-review.googlesource.com/579367
Commit-Queue: Andreas Haas <ahaas@chromium.org>
Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#46811}
parent 0b7361d1
......@@ -5,6 +5,7 @@
#ifndef V8_BOXED_FLOAT_H_
#define V8_BOXED_FLOAT_H_
#include <cmath>
#include "src/base/macros.h"
namespace v8 {
......@@ -22,7 +23,11 @@ class Float32 {
// This constructor does not guarantee that bit pattern of the input value
// is preserved if the input is a NaN.
explicit Float32(float value) : bit_pattern_(bit_cast<uint32_t>(value)) {}
explicit Float32(float value) : bit_pattern_(bit_cast<uint32_t>(value)) {
// Check that the provided value is not a NaN, because the bit pattern of a
// NaN may be changed by a bit_cast, e.g. for signalling NaNs on ia32.
DCHECK(!std::isnan(value));
}
uint32_t get_bits() const { return bit_pattern_; }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment