• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2018 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef V8_OBJECTS_HEAP_NUMBER_H_
6 #define V8_OBJECTS_HEAP_NUMBER_H_
7 
8 #include "src/objects/primitive-heap-object.h"
9 
10 // Has to be the last include (doesn't have include guards):
11 #include "src/objects/object-macros.h"
12 
13 namespace v8 {
14 namespace internal {
15 
16 #include "torque-generated/src/objects/heap-number-tq.inc"
17 
18 // The HeapNumber class describes heap allocated numbers that cannot be
19 // represented in a Smi (small integer).
20 class HeapNumber
21     : public TorqueGeneratedHeapNumber<HeapNumber, PrimitiveHeapObject> {
22  public:
23   inline uint64_t value_as_bits() const;
24   inline void set_value_as_bits(uint64_t bits);
25 
26   inline int get_exponent();
27   inline int get_sign();
28 
29   // Layout description.
30   // IEEE doubles are two 32 bit words.  The first is just mantissa, the second
31   // is a mixture of sign, exponent and mantissa. The offsets of two 32 bit
32   // words within double numbers are endian dependent and they are set
33   // accordingly.
34 #if defined(V8_TARGET_LITTLE_ENDIAN)
35   static const int kMantissaOffset = kValueOffset;
36   static const int kExponentOffset = kValueOffset + 4;
37 #elif defined(V8_TARGET_BIG_ENDIAN)
38   static const int kMantissaOffset = kValueOffset + 4;
39   static const int kExponentOffset = kValueOffset;
40 #else
41 #error Unknown byte ordering
42 #endif
43 
44   static const uint32_t kSignMask = 0x80000000u;
45   static const uint32_t kExponentMask = 0x7ff00000u;
46   static const uint32_t kMantissaMask = 0xfffffu;
47   static const int kMantissaBits = 52;
48   static const int kExponentBits = 11;
49   static const int kExponentBias = 1023;
50   static const int kExponentShift = 20;
51   static const int kInfinityOrNanExponent =
52       (kExponentMask >> kExponentShift) - kExponentBias;
53   static const int kMantissaBitsInTopWord = 20;
54   static const int kNonMantissaBitsInTopWord = 12;
55 
56   DECL_PRINTER(HeapNumber)
57   V8_EXPORT_PRIVATE void HeapNumberShortPrint(std::ostream& os);
58 
59   TQ_OBJECT_CONSTRUCTORS(HeapNumber)
60 };
61 
62 }  // namespace internal
63 }  // namespace v8
64 
65 #include "src/objects/object-macros-undef.h"
66 
67 #endif  // V8_OBJECTS_HEAP_NUMBER_H_
68