/src/hermes/include/hermes/VM/BoxedDouble.h
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) Meta Platforms, Inc. and affiliates. |
3 | | * |
4 | | * This source code is licensed under the MIT license found in the |
5 | | * LICENSE file in the root directory of this source tree. |
6 | | */ |
7 | | |
8 | | #ifndef HERMES_VM_BOXEDDOUBLE_H |
9 | | #define HERMES_VM_BOXEDDOUBLE_H |
10 | | |
11 | | #include "hermes/VM/Runtime.h" |
12 | | |
13 | | namespace hermes { |
14 | | namespace vm { |
15 | | |
16 | | /// A fixed size GCCell used to store a single immutable double. This is used by |
17 | | /// SmallHermesValue to store numbers that cannot be represented as small |
18 | | /// integers. |
19 | | class BoxedDouble final : public GCCell { |
20 | | friend void BoxedDoubleBuildMeta(const GCCell *cell, Metadata::Builder &mb); |
21 | | |
22 | | static const VTable vt; |
23 | | |
24 | | double value_; |
25 | | |
26 | | public: |
27 | 4.08k | static constexpr CellKind getCellKind() { |
28 | 4.08k | return CellKind::BoxedDoubleKind; |
29 | 4.08k | } |
30 | 0 | static bool classof(const GCCell *cell) { |
31 | 0 | return cell->getKind() == CellKind::BoxedDoubleKind; |
32 | 0 | } |
33 | | |
34 | 2.04k | static BoxedDouble *create(double d, Runtime &runtime) { |
35 | 2.04k | return runtime.makeAFixed<BoxedDouble>(d); |
36 | 2.04k | } |
37 | | |
38 | 2.04k | BoxedDouble(double d) : value_(d) {} |
39 | | |
40 | 0 | double get() const { |
41 | 0 | return value_; |
42 | 0 | } |
43 | | }; |
44 | | |
45 | | } // namespace vm |
46 | | } // namespace hermes |
47 | | |
48 | | #endif // HERMES_VM_BOXEDDOUBLE_H |