BigInt.h 971 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /*
  2. * Copyright (c) 2020-2022, Linus Groh <linusg@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/Error.h>
  8. #include <AK/String.h>
  9. #include <AK/StringView.h>
  10. #include <LibCrypto/BigInt/SignedBigInteger.h>
  11. #include <LibJS/Heap/Cell.h>
  12. #include <LibJS/Heap/CellAllocator.h>
  13. namespace JS {
  14. class BigInt final : public Cell {
  15. JS_CELL(BigInt, Cell);
  16. JS_DECLARE_ALLOCATOR(BigInt);
  17. public:
  18. [[nodiscard]] static NonnullGCPtr<BigInt> create(VM&, Crypto::SignedBigInteger);
  19. virtual ~BigInt() override = default;
  20. Crypto::SignedBigInteger const& big_integer() const { return m_big_integer; }
  21. ErrorOr<String> to_string() const;
  22. ByteString to_byte_string() const { return ByteString::formatted("{}n", m_big_integer.to_base_deprecated(10)); }
  23. private:
  24. explicit BigInt(Crypto::SignedBigInteger);
  25. Crypto::SignedBigInteger m_big_integer;
  26. };
  27. ThrowCompletionOr<BigInt*> number_to_bigint(VM&, Value);
  28. }