Fix rounding errors for range node when using float inputs and integer outputs

And add extra tests
This commit is contained in:
Dave Conway-Jones
2025-08-28 15:18:02 +01:00
parent 9ad329e5a1
commit 7b51f30d11
2 changed files with 12 additions and 0 deletions

View File

@@ -24,6 +24,10 @@ module.exports = function(RED) {
this.maxin = Number(n.maxin);
this.minout = Number(n.minout);
this.maxout = Number(n.maxout);
if (this.round) {
this.maxout = Math.floor(this.maxout);
this.minout = Math.ceil(this.minout);
}
this.property = n.property||"payload";
var node = this;

View File

@@ -106,6 +106,14 @@ describe('range Node', function() {
genericRangeTest("clamp", 0, 10, 0, 1000, false, -1, 0, done);
});
it('clamps numbers within a range - above max fp', function(done) {
genericRangeTest("clamp", 0, 9.5, 0.5, 100.5, true, 13.1, 100, done);
});
it('clamps numbers within a range - below min fp', function(done) {
genericRangeTest("clamp", 0, 9.5, 0.3, 100.5, true, -13.1, 1, done);
});
it('drops msg if in drop mode and input outside range', function(done) {
var flow = [{"id":"rangeNode1","type":"range","minin":2,"maxin":8,"minout":20,"maxout":80,"action":"drop","round":true,"name":"rangeNode","wires":[["helperNode1"]]},
{id:"helperNode1", type:"helper", wires:[]}];