mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 00:07:35 +00:00
LibJS: Add all of the DataView.prototype.set* methods
This commit is contained in:
parent
c54b9a6920
commit
d7a70eb77c
8 changed files with 203 additions and 0 deletions
|
@ -55,6 +55,14 @@ String SignedBigInteger::to_base10() const
|
|||
return builder.to_string();
|
||||
}
|
||||
|
||||
u64 SignedBigInteger::to_u64() const
|
||||
{
|
||||
u64 unsigned_value = m_unsigned_data.to_u64();
|
||||
if (!m_sign)
|
||||
return unsigned_value;
|
||||
return ~(unsigned_value - 1); // equivalent to `-unsigned_value`, but doesnt trigger UBSAN
|
||||
}
|
||||
|
||||
FLATTEN SignedBigInteger SignedBigInteger::plus(const SignedBigInteger& other) const
|
||||
{
|
||||
// If both are of the same sign, just add the unsigned data and return.
|
||||
|
|
|
@ -65,6 +65,8 @@ public:
|
|||
static SignedBigInteger from_base10(StringView str);
|
||||
String to_base10() const;
|
||||
|
||||
u64 to_u64() const;
|
||||
|
||||
const UnsignedBigInteger& unsigned_value() const { return m_unsigned_data; }
|
||||
const Vector<u32, STARTING_WORD_SIZE> words() const { return m_unsigned_data.words(); }
|
||||
bool is_negative() const { return m_sign; }
|
||||
|
|
|
@ -102,6 +102,17 @@ String UnsignedBigInteger::to_base10() const
|
|||
return builder.to_string();
|
||||
}
|
||||
|
||||
u64 UnsignedBigInteger::to_u64() const
|
||||
{
|
||||
VERIFY(sizeof(Word) == 4);
|
||||
if (!length())
|
||||
return 0;
|
||||
u64 value = m_words[0];
|
||||
if (length() > 1)
|
||||
value |= static_cast<u64>(m_words[1]) << 32;
|
||||
return value;
|
||||
}
|
||||
|
||||
void UnsignedBigInteger::set_to_0()
|
||||
{
|
||||
m_words.clear_with_capacity();
|
||||
|
|
|
@ -56,6 +56,8 @@ public:
|
|||
static UnsignedBigInteger from_base10(const String& str);
|
||||
String to_base10() const;
|
||||
|
||||
u64 to_u64() const;
|
||||
|
||||
const Vector<Word, STARTING_WORD_SIZE>& words() const { return m_words; }
|
||||
|
||||
void set_to_0();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue