Community Tip - Did you get called away in the middle of writing a post? Don't worry you can find your unfinished post later in the Drafts section of your profile page. X
So i was working on some big number within thingworx and got some unexpected results.
var BIGINT_OUT_OF_BOUNDS = Number("-9223372036854775805");
result = BIGINT_OUT_OF_BOUNDS;
This will result in -9223372036854776000
If you read the javascript documentation this is understandable.
So i did:
var BIGINT_OUT_OF_BOUNDS = BigInt("-9223372036854775805");
result = BIGINT_OUT_OF_BOUNDS;
This will result in an error: Error executing service BigInt. Message :: ReferenceError: "BigInt" is not defined. - See Script Error Log for more details.
Witch is understandable because thingworx uses Rhino 1.7.11. And BigInt is only implemented from Rhino version 1.7.14.
I must be missing something.
So my question is, how am i supposed to work with big numbers?
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.
Just curious, why do you need to work with BigInt?
Well,
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 BigInt is a perfect match.
At the edge of each number we reserve a few numbers for error statuses.
So for a bigint we use -9223372036854775805 to indicate that we received a number that is not in the bigInt range.
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 -9,223,372,036,854,775,804 and 9,223,372,036,854,775,807.
if not we would insert -9223372036854775805
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"
For this use case, why not use a string comparison, which also supports < and >?
One possible alternative is to write a Java extension to handle these types of cases. Not sure if this is the latest docs, but it can get you started. Your use case should be fairly simple to code up: https://community.ptc.com/sejnu66972/attachments/sejnu66972/twxdevs/8416/1/thingworx_extension_development_user_guide.pdf