JS_NewDoubleValue

  • Revision slug: SpiderMonkey/JSAPI_Reference/JS_NewDoubleValue
  • Revision title: JS_NewDoubleValue
  • Revision id: 69184
  • Created:
  • Creator: Jorend
  • Is current revision? No
  • Comment style, merge

Revision Content

{{template.Jsapi_ref_header("JS_NewNumberValue")}}

Convert a C floating-point number of type jsdouble to a jsval.

Syntax

JSBool JS_NewNumberValue(JSContext *cx, jsdouble d, jsval *rval);

JSBool JS_NewDoubleValue(JSContext *cx, jsdouble d, jsval *rval);
Name Type Description
cx JSContext * The context in which to create the new number. {{wiki.template('Jsapi-requires-request')}}
d jsdouble The numeric value to convert.
rval jsval * Out parameter. On success, *rval receives a JavaScript number with the value d.

Description

JS_NewNumberValue converts a C floating-point number of type jsdouble to jsval, the type of JavaScript values. JS_NewDoubleValue does exactly the same thing, except for details of how the resulting jsval is represented in memory.

JS_NewDoubleValue always creates a floating-point jsval. JS_NewNumberValue creates an unboxed integer jsval if d can be exactly represented that way. In the current implementation, this may use less memory.

Some space for the new value may be allocated from the JS garbage collection heap. In this case, the value is subject to garbage collection until you protect against it using a local root, an object property, or the JS_AddRoot function.

On success, a number is assigned to *rval and the function returns JS_TRUE. Otherwise it returns JS_FALSE and the value left in *rval is unspecified.

{{template.LXRSearch("ident", "i", "JS_NewNumberValue")}} {{template.LXRSearch("ident", "i", "JS_NewDoubleValue")}}

Revision Source

<p>{{template.Jsapi_ref_header("JS_NewNumberValue")}}
</p><p>Convert a C floating-point number of type <code>jsdouble</code> to a <code>jsval</code>.
</p>
<h2 name="Syntax"> Syntax </h2>
<pre class="eval"><a href="en/JSBool">JSBool</a> <b>JS_NewNumberValue</b>(<a href="en/JSContext">JSContext</a> *cx, <a href="en/Jsdouble">jsdouble</a> d, <a href="en/Jsval">jsval</a> *rval);

<a href="en/JSBool">JSBool</a> <b>JS_NewDoubleValue</b>(<a href="en/JSContext">JSContext</a> *cx, <a href="en/Jsdouble">jsdouble</a> d, <a href="en/Jsval">jsval</a> *rval);
</pre>
<table class="fullwidth-table">
<tbody><tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
</tr>
<tr>
<td><code>cx</code></td>
<td><code><a href="en/JSContext">JSContext</a> *</code></td>
<td>The context in which to create the new number.
{{wiki.template('Jsapi-requires-request')}}</td>
</tr>
<tr>
<td><code>d</code></td>
<td><code><a href="en/Jsdouble">jsdouble</a></code></td>
<td>The numeric value to convert.</td>
</tr>
<tr>
<td><code>rval</code></td>
<td><code><a href="en/Jsval">jsval</a> *</code></td>
<td>Out parameter.  On success, <code>*rval</code> receives a JavaScript number with the value <code>d</code>.</td>
</tr>
</tbody></table>
<h2 name="Description"> Description </h2>
<p><b><code>JS_NewNumberValue</code></b> converts a C floating-point number of type <code><a href="en/Jsdouble">jsdouble</a></code> to <code><a href="en/Jsval">jsval</a></code>, the type of JavaScript values.  <b><code>JS_NewDoubleValue</code></b> does exactly the same thing, except for details of how the resulting <code>jsval</code> is represented in memory.
</p><p><code>JS_NewDoubleValue</code> always creates a floating-point <code>jsval</code>.  <code>JS_NewNumberValue</code> creates an unboxed integer <code>jsval</code> if <code>d</code> can be exactly represented that way.  In the current implementation, this may use less memory.
</p><p>Some space for the new value may be allocated from the JS garbage collection heap.  In this case, the value is subject to garbage collection until you protect against it using a local root, an object property, or the <code><a href="en/JS_AddRoot">JS_AddRoot</a></code> function.
</p><p>On success, a number is assigned to <code>*rval</code> and the function returns <code>JS_TRUE</code>. Otherwise it returns <code>JS_FALSE</code> and the value left in <code>*rval</code> is unspecified.
</p><p>{{template.LXRSearch("ident", "i", "JS_NewNumberValue")}}
{{template.LXRSearch("ident", "i", "JS_NewDoubleValue")}}
</p>
Revert to this revision