diff --git a/src/core/graph/nodes/data/Equals.ts b/src/core/graph/nodes/data/Equals.ts index a69acf6f..76a5bd41 100644 --- a/src/core/graph/nodes/data/Equals.ts +++ b/src/core/graph/nodes/data/Equals.ts @@ -1,5 +1,5 @@ import type { NodeDef } from '../../NodeRegistry'; -import { asEntity, asString, nearlyEqual } from '../../values'; +import { asEntity, asString, nearlyEqual, type Value } from '../../values'; import { any, bool } from '../shared'; export const Equals: NodeDef = { @@ -15,9 +15,21 @@ export const Equals: NodeDef = { const a = asEntity(inputs.a); const b = asEntity(inputs.b); if (a || b) return { outputs: { result: a === b } }; - if (typeof inputs.a === 'number' && typeof inputs.b === 'number') { - return { outputs: { result: nearlyEqual(inputs.a, inputs.b) } }; + // An inline field on an `any` pin is text, so a typed 130 arrives as "130": with a number on + // the other side it still counts as that number (#224). + const x = numberOf(inputs.a); + const y = numberOf(inputs.b); + if (x !== null && y !== null && (typeof inputs.a === 'number' || typeof inputs.b === 'number')) { + return { outputs: { result: nearlyEqual(x, y) } }; } return { outputs: { result: asString(inputs.a) === asString(inputs.b) } }; }, }; + +/** A number, or text that is one ("130", " 1.5 "); empty text is not 0 here. */ +function numberOf(value: Value | undefined): number | null { + if (typeof value === 'number') return value; + if (typeof value !== 'string' || value.trim() === '') return null; + const n = Number(value); + return Number.isFinite(n) ? n : null; +} diff --git a/tests/core/node-catalog.test.ts b/tests/core/node-catalog.test.ts index 736f564a..d3d183e5 100644 --- a/tests/core/node-catalog.test.ts +++ b/tests/core/node-catalog.test.ts @@ -691,6 +691,14 @@ const CASES: Record = { outputs: { result: true }, }, { name: 'two numbers still tell 6.001 from 6', inputs: { a: 6.001, b: 6 }, outputs: { result: false } }, + // The inline field of an `any` pin is text: a typed 130 against time - late at 130 s. + { + name: 'a noisy number equals the typed text 130', + inputs: { a: 129.99999999999997, b: '130' }, + outputs: { result: true }, + }, + { name: 'empty text is not 0', inputs: { a: 0, b: '' }, outputs: { result: false } }, + { name: 'two texts still compare as text', inputs: { a: '1.0', b: '1' }, outputs: { result: false } }, ], Compare: [ { name: 'less than', inputs: { a: 1, b: 2 }, params: { op: '<' }, outputs: { result: true } },