map: Produce 0 instead of NaN for non-numeric string values

This has been a problem for...ever, but the old classification system (and
calculations) had `||0` for ever variable reference, whereas the new one
does not; NaNs result in undefined behavior in the new classification
system, since those values are not expected to exist.

This ought to have automated tests, but it will be rewritten in TAMER.

DEV-10484
main
Mike Gerwitz 2022-03-03 11:02:16 -05:00
parent fb5f38d14c
commit 501a9441a5
3 changed files with 15 additions and 4 deletions

View File

@ -14,6 +14,17 @@ commits that introduce the changes. To make a new release, run
`tools/mkrelease`, which will handle updating the heading for you.
NEXT
====
This is a bugfix release.
Compiler
--------
- Input maps will now ensure that non-numeric string values result in `0`
rather than `NaN`, the latter of which results in undefined behavior in
the new classification system.
v19.0.0 (2022-03-01)
====================
This version includes a backwards-incomplatible change to enable the new

View File

@ -2414,7 +2414,7 @@
{
// TODO: error
if ( Array.isArray( input ) ) input = input[0];
return ( input === '' || input === undefined ) ? value : +input;
return ( input === '' || input === undefined ) ? value : +input||0;
}
// TODO: error for both
@ -2428,9 +2428,9 @@
return input.map( function( x ) {
return ( depth === 2 )
? Array.isArray( x )
? x.map( function(s) { return +s; } )
? x.map( function(s) { return +s||0; } )
: [ x ]
: ( x === '' || x === undefined ) ? value : +x;
: ( x === '' || x === undefined ) ? value : +x||0;
} );
}

View File

@ -796,7 +796,7 @@
<call-template name="lvmc:gen-input-default">
<with-param name="sym" select="$sym" />
<with-param name="from-str">
<text>''+val[i]</text>
<text>+val[i]||0</text>
</with-param>
<!-- We have to reduce the nesting level by one because of
our outer loop, but we do not want to go below 0, which