ladybird/Libraries/LibJS/Runtime/BigInt.h

41 lines
978 B
C
Raw Normal View History

2020-06-06 01:14:10 +01:00
/*
* Copyright (c) 2020-2022, Linus Groh <linusg@serenityos.org>
2020-06-06 01:14:10 +01:00
*
* SPDX-License-Identifier: BSD-2-Clause
2020-06-06 01:14:10 +01:00
*/
#pragma once
#include <AK/Error.h>
#include <AK/String.h>
#include <AK/StringView.h>
2020-06-06 01:14:10 +01:00
#include <LibCrypto/BigInt/SignedBigInteger.h>
#include <LibGC/CellAllocator.h>
#include <LibJS/Heap/Cell.h>
2020-06-06 01:14:10 +01:00
namespace JS {
2025-06-28 21:39:13 -07:00
class JS_API BigInt final : public Cell {
GC_CELL(BigInt, Cell);
GC_DECLARE_ALLOCATOR(BigInt);
2020-06-06 01:14:10 +01:00
public:
[[nodiscard]] static GC::Ref<BigInt> create(VM&, Crypto::SignedBigInteger);
virtual ~BigInt() override = default;
2020-06-06 01:14:10 +01:00
2022-04-01 20:58:27 +03:00
Crypto::SignedBigInteger const& big_integer() const { return m_big_integer; }
ErrorOr<String> to_string() const;
ByteString to_byte_string() const { return ByteString::formatted("{}n", MUST(m_big_integer.to_base(10))); }
2020-06-06 01:14:10 +01:00
private:
explicit BigInt(Crypto::SignedBigInteger);
2020-06-06 01:14:10 +01:00
Crypto::SignedBigInteger m_big_integer;
};
2025-06-28 21:39:13 -07:00
JS_API ThrowCompletionOr<GC::Ref<BigInt>> number_to_bigint(VM&, Value);
2020-06-06 01:14:10 +01:00
}