<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: BigInt in javascript in ThingWorx Developers</title>
    <link>https://www.ptcusercommunity.com/t5/ThingWorx-Developers/BigInt-in-javascript/m-p/914812#M64645</link>
    <description>&lt;P&gt;Well,&lt;/P&gt;&lt;P&gt;We use SQL server to store data. Some whole numbers dont seem to fit a float(not precise enough) nor a integer(to small), but the &lt;A href="https://learn.microsoft.com/en-us/azure/databricks/sql/language-manual/data-types/bigint-type" target="_blank" rel="noopener"&gt;BigInt&lt;/A&gt; is a perfect match.&lt;/P&gt;&lt;P&gt;At the edge of each number we reserve a few numbers for error statuses.&lt;/P&gt;&lt;P&gt;So for a bigint we use -9223372036854775805 to indicate that we received a number that is not in the bigInt range.&lt;/P&gt;&lt;P&gt;so in stead of an sql error(' Arithmetic overflow error') that results in no new record, we would check if the input value is between&amp;nbsp; -9,223,372,036,854,775,804 and 9,223,372,036,854,775,807.&lt;/P&gt;&lt;P&gt;if not we would insert -9223372036854775805&lt;/P&gt;&lt;P&gt;We prefer this above having a null in the database. because we can check why it was not inserted. and visualise that to the customer. as "Out of range"&lt;/P&gt;</description>
    <pubDate>Mon, 27 Nov 2023 12:14:34 GMT</pubDate>
    <dc:creator>JU_10321794</dc:creator>
    <dc:date>2023-11-27T12:14:34Z</dc:date>
    <item>
      <title>BigInt in javascript</title>
      <link>https://www.ptcusercommunity.com/t5/ThingWorx-Developers/BigInt-in-javascript/m-p/914789#M64636</link>
      <description>&lt;P&gt;So i was working on some big number within thingworx and got some unexpected results.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var BIGINT_OUT_OF_BOUNDS	= Number("-9223372036854775805");
result = BIGINT_OUT_OF_BOUNDS;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This will result in -9223372036854776000&lt;/P&gt;&lt;P&gt;If you read the javascript &lt;A href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number" target="_blank" rel="noopener"&gt;documentation&lt;/A&gt; this is understandable.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So i did:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var BIGINT_OUT_OF_BOUNDS	= BigInt("-9223372036854775805");
result = BIGINT_OUT_OF_BOUNDS;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This will result in an error: Error executing service BigInt. Message :: ReferenceError: "BigInt" is not defined. - See Script Error Log for more details.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Witch is understandable because &lt;A href="https://support.ptc.com/help/thingworx/platform/r9/en/index.html#page/ThingWorx/Help/Composer/Things/ThingServices/RhinoJavaScriptEngine.html#" target="_blank" rel="noopener"&gt;thingworx uses&lt;/A&gt; Rhino 1.7.11. And &lt;A href="https://github.com/mozilla/rhino/blob/master/RELEASE-NOTES.md" target="_blank" rel="noopener"&gt;BigInt is only implemented&lt;/A&gt; from Rhino version 1.7.14.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I must be missing something.&lt;/P&gt;&lt;P&gt;So my question is, how am i supposed to work with big numbers?&lt;/P&gt;</description>
      <pubDate>Mon, 27 Nov 2023 10:05:06 GMT</pubDate>
      <guid>https://www.ptcusercommunity.com/t5/ThingWorx-Developers/BigInt-in-javascript/m-p/914789#M64636</guid>
      <dc:creator>JU_10321794</dc:creator>
      <dc:date>2023-11-27T10:05:06Z</dc:date>
    </item>
    <item>
      <title>Re: BigInt in javascript</title>
      <link>https://www.ptcusercommunity.com/t5/ThingWorx-Developers/BigInt-in-javascript/m-p/914798#M64639</link>
      <description>&lt;P&gt;Besides replacing the Rhino library, which is not a supported, neither recommended operation from my PTC perspective, I don't see a way to use it.&lt;/P&gt;
&lt;P&gt;Just curious, why do you need to work with BigInt?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Nov 2023 11:20:33 GMT</pubDate>
      <guid>https://www.ptcusercommunity.com/t5/ThingWorx-Developers/BigInt-in-javascript/m-p/914798#M64639</guid>
      <dc:creator>VladimirRosu</dc:creator>
      <dc:date>2023-11-27T11:20:33Z</dc:date>
    </item>
    <item>
      <title>Re: BigInt in javascript</title>
      <link>https://www.ptcusercommunity.com/t5/ThingWorx-Developers/BigInt-in-javascript/m-p/914812#M64645</link>
      <description>&lt;P&gt;Well,&lt;/P&gt;&lt;P&gt;We use SQL server to store data. Some whole numbers dont seem to fit a float(not precise enough) nor a integer(to small), but the &lt;A href="https://learn.microsoft.com/en-us/azure/databricks/sql/language-manual/data-types/bigint-type" target="_blank" rel="noopener"&gt;BigInt&lt;/A&gt; is a perfect match.&lt;/P&gt;&lt;P&gt;At the edge of each number we reserve a few numbers for error statuses.&lt;/P&gt;&lt;P&gt;So for a bigint we use -9223372036854775805 to indicate that we received a number that is not in the bigInt range.&lt;/P&gt;&lt;P&gt;so in stead of an sql error(' Arithmetic overflow error') that results in no new record, we would check if the input value is between&amp;nbsp; -9,223,372,036,854,775,804 and 9,223,372,036,854,775,807.&lt;/P&gt;&lt;P&gt;if not we would insert -9223372036854775805&lt;/P&gt;&lt;P&gt;We prefer this above having a null in the database. because we can check why it was not inserted. and visualise that to the customer. as "Out of range"&lt;/P&gt;</description>
      <pubDate>Mon, 27 Nov 2023 12:14:34 GMT</pubDate>
      <guid>https://www.ptcusercommunity.com/t5/ThingWorx-Developers/BigInt-in-javascript/m-p/914812#M64645</guid>
      <dc:creator>JU_10321794</dc:creator>
      <dc:date>2023-11-27T12:14:34Z</dc:date>
    </item>
    <item>
      <title>Re: BigInt in javascript</title>
      <link>https://www.ptcusercommunity.com/t5/ThingWorx-Developers/BigInt-in-javascript/m-p/914819#M64648</link>
      <description>&lt;P&gt;For this use case, why not use a string comparison, which also supports &amp;lt; and &amp;gt;?&lt;/P&gt;</description>
      <pubDate>Mon, 27 Nov 2023 12:33:33 GMT</pubDate>
      <guid>https://www.ptcusercommunity.com/t5/ThingWorx-Developers/BigInt-in-javascript/m-p/914819#M64648</guid>
      <dc:creator>Rocko</dc:creator>
      <dc:date>2023-11-27T12:33:33Z</dc:date>
    </item>
    <item>
      <title>Re: BigInt in javascript</title>
      <link>https://www.ptcusercommunity.com/t5/ThingWorx-Developers/BigInt-in-javascript/m-p/915113#M64660</link>
      <description>&lt;P&gt;One possible alternative is to write a Java extension to handle these types of cases.&amp;nbsp; Not sure if this is the latest docs, but it can get you started.&amp;nbsp; Your use case should be fairly simple to code up:&amp;nbsp;&amp;nbsp;&lt;A href="https://community.ptc.com/sejnu66972/attachments/sejnu66972/twxdevs/8416/1/thingworx_extension_development_user_guide.pdf" target="_blank"&gt;https://community.ptc.com/sejnu66972/attachments/sejnu66972/twxdevs/8416/1/thingworx_extension_development_user_guide.pdf&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Nov 2023 13:04:32 GMT</pubDate>
      <guid>https://www.ptcusercommunity.com/t5/ThingWorx-Developers/BigInt-in-javascript/m-p/915113#M64660</guid>
      <dc:creator>nmilleson</dc:creator>
      <dc:date>2023-11-28T13:04:32Z</dc:date>
    </item>
  </channel>
</rss>

