From 2ffa054574839b7f1e2c44e8a26e62b0d632d01e Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 8 Apr 2020 11:22:20 +0200 Subject: [PATCH] LibJS: Add Value::to_double() for convenience --- Libraries/LibJS/Runtime/Value.cpp | 5 +++++ Libraries/LibJS/Runtime/Value.h | 1 + 2 files changed, 6 insertions(+) diff --git a/Libraries/LibJS/Runtime/Value.cpp b/Libraries/LibJS/Runtime/Value.cpp index fa489a65b7..889e4e18f6 100644 --- a/Libraries/LibJS/Runtime/Value.cpp +++ b/Libraries/LibJS/Runtime/Value.cpp @@ -170,6 +170,11 @@ i32 Value::to_i32() const return static_cast(to_number().as_double()); } +double Value::to_double() const +{ + return to_number().as_double(); +} + Value greater_than(Value lhs, Value rhs) { return Value(lhs.to_number().as_double() > rhs.to_number().as_double()); diff --git a/Libraries/LibJS/Runtime/Value.h b/Libraries/LibJS/Runtime/Value.h index dfdcaa8382..7a5820e6b0 100644 --- a/Libraries/LibJS/Runtime/Value.h +++ b/Libraries/LibJS/Runtime/Value.h @@ -146,6 +146,7 @@ public: bool to_boolean() const; Value to_number() const; i32 to_i32() const; + double to_double() const; Object* to_object(Heap&) const;