newcat / baklavajs

Graph / node editor in the browser using VueJS
http://baklava.tech
MIT License
1.52k stars 113 forks source link

Increment/Decrement on NumberInterface creates weird precision #327

Closed sgramsay closed 8 months ago

sgramsay commented 10 months ago

Taking the below example node code, utilising the increment/decrement handles results in weird precision issues, am I missing something or is this a bug? Entering numbers directly is fine.

image

import { defineNode, NodeInterface, NumberInterface, SelectInterface } from "baklavajs";

export default defineNode({
    type: "MathNode",
    inputs: {
        number1: () => new NumberInterface("A", 1),
        number2: () => new NumberInterface("B", 10),
        operation: () => new SelectInterface("Operation", "Add", ["Add", "Subtract"]).setPort(false),
    },
    outputs: {
        output: () => new NodeInterface("Output", 0),
    },
    calculate({ number1, number2, operation }) {
        let output: Number
        console.log(number1,"-",number2) // Outputs  1.6000000000000005 '0' - 10
        if (operation === "Add") {
            output = number1 + number2;
        } else if (operation === "Subtract") {
            output = number1 - number2;
        } else {
            throw new Error("Unknown operation: " + operation);
        }
        return { output };
    },
});
sgramsay commented 10 months ago

V2 Beta 5 BTW

newcat commented 8 months ago

Fixed in v2.3.0