BigInt.h 917 B

1234567891011121314151617181920212223242526272829303132333435363738
  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. namespace JS {
  13. class BigInt final : public Cell {
  14. JS_CELL(BigInt, Cell);
  15. public:
  16. [[nodiscard]] static NonnullGCPtr<BigInt> create(VM&, Crypto::SignedBigInteger);
  17. virtual ~BigInt() override = default;
  18. Crypto::SignedBigInteger const& big_integer() const { return m_big_integer; }
  19. ErrorOr<String> to_string() const;
  20. DeprecatedString to_deprecated_string() const { return DeprecatedString::formatted("{}n", m_big_integer.to_base_deprecated(10)); }
  21. private:
  22. explicit BigInt(Crypto::SignedBigInteger);
  23. Crypto::SignedBigInteger m_big_integer;
  24. };
  25. ThrowCompletionOr<BigInt*> number_to_bigint(VM&, Value);
  26. }