Open sjbarag opened 4 years ago
Brightscript Debugger> a = [0,1,2,3]
Brightscript Debugger> b = 1.9999999
Brightscript Debugger> ?b
2
Brightscript Debugger> ?a[b]
1
-------------------------------------------------------
Brightscript Debugger> var
args roAssociativeArray refcnt=3 count:7
global Interface:ifGlobal
m roAssociativeArray refcnt=2 count:6
screen roSGScreen refcnt=1
appinfo roAppManager refcnt=1
inputhandler roInput refcnt=1
syslog roSystemLog refcnt=1
scene roSGNode:RootScene refcnt=1
texttospeech roTextToSpeech refcnt=1
deeplinknode roSGNode:ContentNode refcnt=1
msg roSGNodeEvent refcnt=1
msgtype String (VT_STR_CONST) val:"roSGNodeEvent"
event <uninitialized>
a roArray refcnt=1 count:4
b Float val:2
While investigating this, it appears toStr
rounds to the nearest hundred thousandths and could make things pretty tricky when debugging! Should we replicate that behavior here: https://github.com/sjbarag/brs/blob/master/src/stdlib/String.ts#L155
That's assuming we are indeed rounding to the nearest hundred thousandths in toStr
Surprisingly, the reference brightscript interpreter allows floating-point indexes into arrays by performing "toward zero" rounding for almost all values. See the following test output for details: