pub struct JsNumber(/* private fields */);
Implementations§
Source§impl JsNumber
impl JsNumber
Sourcepub fn int32(env: NapiEnv, value: i32) -> NapiResult<JsNumber>
pub fn int32(env: NapiEnv, value: i32) -> NapiResult<JsNumber>
This API is used to convert from the C int32_t type to the JavaScript number type. The JavaScript number type is described in Section 6.1.6 of the ECMAScript Language Specification.
Sourcepub fn uint32(env: NapiEnv, value: u32) -> NapiResult<JsNumber>
pub fn uint32(env: NapiEnv, value: u32) -> NapiResult<JsNumber>
This API is used to convert from the C uint32_t type to the JavaScript number type. The JavaScript number type is described in Section 6.1.6 of the ECMAScript Language Specification.
Sourcepub fn int64(env: NapiEnv, value: i64) -> NapiResult<JsNumber>
pub fn int64(env: NapiEnv, value: i64) -> NapiResult<JsNumber>
This API is used to convert from the C int64_t type to the JavaScript number type. The JavaScript number type is described in Section 6.1.6 of the ECMAScript Language Specification. Note the complete range of int64_t cannot be represented with full precision in JavaScript. Integer values outside the range of Number.MIN_SAFE_INTEGER -(253 - 1) - Number.MAX_SAFE_INTEGER (253 - 1) will lose precision.
Sourcepub fn double(env: NapiEnv, value: f64) -> NapiResult<JsNumber>
pub fn double(env: NapiEnv, value: f64) -> NapiResult<JsNumber>
This API is used to convert from the C double type to the JavaScript number type. The JavaScript number type is described in Section 6.1.6 of the ECMAScript Language Specification.
Sourcepub fn get_value_int32(&self) -> NapiResult<i32>
pub fn get_value_int32(&self) -> NapiResult<i32>
If a non-number napi_value is passed in napi_number_expected. This API returns the C int32 primitive equivalent of the given JavaScript number. If the number exceeds the range of the 32 bit integer, then the result is truncated to the equivalent of the bottom 32 bits. This can result in a large positive number becoming a negative number if the value is > 231 - 1. Non-finite number values (NaN, +Infinity, or -Infinity) set the result to zero.
Sourcepub fn get_value_uint32(&self) -> NapiResult<u32>
pub fn get_value_uint32(&self) -> NapiResult<u32>
If a non-number napi_value is passed in it returns napi_number_expected. This API returns the C primitive equivalent of the given napi_value as a uint32_t.
Sourcepub fn get_value_int64(&self) -> NapiResult<i64>
pub fn get_value_int64(&self) -> NapiResult<i64>
If a non-number napi_value is passed in it returns napi_number_expected. This API returns the C int64 primitive equivalent of the given JavaScript number. number values outside the range of Number.MIN_SAFE_INTEGER -(253 - 1) - Number.MAX_SAFE_INTEGER (253 - 1) will lose precision. Non-finite number values (NaN, +Infinity, or -Infinity) set the result to zero.
Sourcepub fn get_value_double(&self) -> NapiResult<f64>
pub fn get_value_double(&self) -> NapiResult<f64>
If a non-number napi_value is passed in it returns napi_number_expected. This API returns the C double primitive equivalent of the given JavaScript number.