Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

@fitbit/sdk 7.2.0-pre.0 or @fitbit/sdk-cli 1.8.0-pre.11 has bug in Math.pow

ANSWERED

consider the following code ...

index.js

import * as mf from "../common/mathFunctions.js"

const bat = mf.bat();
console.log("mf.foo " + bat.foo);
console.log("mf.bar " + bat.bar);
console.log("mf.baz " + bat.baz);

../common/mathFuncitons.js

export function bat () {
let foo1 = Math.pow(-1, 2);
let bar1 = Math.pow(Math.abs(-1), 2);
let baz1 = Math.pow(-0.3668, 2);
return {foo: foo1, bar: bar1, baz: baz1};
}

The following returns NaN for raising a negative number unless it is made positive by Math.pow().

From the console I get.

Launching app
[10:37:23 AM] App: pc.foo NaN (app/index.js:11,1)
[10:37:23 AM] App: pc.bar 1 (app/index.js:12,1)
[10:37:23 AM] App: pc.baz NaN (app/index.js:13,1)

If I back off the @SDK and @SDK-cli to 6.1.0 and 1.7.3 respectively, I get

Launching app
[10:46:31 AM] App: App Closed
[10:46:31 AM] App: App Started
[10:46:31 AM] App: pc.foo 1 (app/index.js:11,1)
[10:46:31 AM] App: pc.bar 1 (app/index.js:12,1)
[10:46:31 AM] App: pc.baz 0.13454224 (app/index.js:13,1)

I don't know enough js to determine where the error exists in the node_modules code, but I thought someone else here might.

Best Answer
0 Votes
1 BEST ANSWER

Accepted Solutions

If you're only squaring things, can't you use x*x ? That will be more computationally efficient; I think .pow is usually implemented using logarithms, which requires mathematical series (even in hardware).

Peter McLennan
Gondwana Software

View best answer in original post

Best Answer
0 Votes
5 REPLIES 5


The following returns NaN for raising a negative number unless it is made positive by Math.pow().


This should read, the following returns NaN for raising a negative number unless it is made positive by Math.abs().

Chris

Best Answer
0 Votes

Since I wanted to file a bug report on this, wherever it occurs, I did some more testing.  I now believe this to be a firmware issue with the Sense 2 firmware 60.20001.194.86.  I get the NaN value for the Math.pow call only when building and sideloading to my Sense 2 watch.  If I build for the Fitbit OS Simulator-stable-0.9.4.exe, I get the correct value.  This means I've had to back off from sdk 7.2.0-pre.0 to sdk 6.2.0-pre.1 and am using sdk-cli 1.8.0-pre.11.  With the sdk 6.2.0-pre.1 and sdk-cli 1.8.0-pre.11 I can build for rhea and hera as well as vulcan and atlas.  When I build for vulcan and atlas, I get the correct result from the Simulator, while building for the Sense 2 gives the NaN values.  I would like to submit a bug report, somewhere, but I don't know where to log it.  If a fitbit employee reads this, could they either log this bug or point me where to log it.

Thanks in advance,

Chris

Best Answer
0 Votes

Hi @chrisjohgorman - you can't file a bug report when using unofficial features that Fitbit aren't supporting.

What you are seeing also is a mix.

Anything you see in the simulator is for older watches (which works) what you may get on the Sense 2 using an unofficial SDK build is indeterminate.

No SDK has been announced for the Sense 2 still.

Clocks built for and running on a Sense won't necessarily run on a Sense 2 using the same source due to faults or different build requirements.

You may hit lucky and it works or it may not. There is nothing you can do about such faults other than use a workaround - different coding for that operation.

Author | ch, passion for improvement.

Best Answer

Hi @Guy_ ,

Thanks for the info.  I have worked around this bug, by encapsulating my Math.pow(variable, 2) calls with a Math.pow(Math.abs(variable), 2).  This fixes the problem, I just thought fitbit should know about this.  (All my Math.pow calls are raised to the second power only, so this works.)  If there's no one / nowhere to log these kind of things, I'll drop it.

Take care,

Chris

Best Answer
0 Votes

If you're only squaring things, can't you use x*x ? That will be more computationally efficient; I think .pow is usually implemented using logarithms, which requires mathematical series (even in hardware).

Peter McLennan
Gondwana Software
Best Answer
0 Votes