From 9d0f87e43fbf471f861f409089208448a3c25118 Mon Sep 17 00:00:00 2001 From: mcDandy Date: Mon, 2 Feb 2026 20:44:20 +0100 Subject: [PATCH] Int<->bool conversion --- README.md | 2 +- more_math/nodes.py | 53 +++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 53 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1765bdc..bbbd7e7 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ You can also get the node from comfy manager under the name of More math. ## Features - functions and variables in math expressions -- Conversion between INT and FLOAT; AUDIO and IMAGE (red - real - strenght of cosine of frequency; blue - imaginary - strenght of sine of frequency; green - log1p of amplitude - just so it looks good to humans) +- Conversion between INT and FLOAT; INT and BOOLEAN; AUDIO and IMAGE (red - real - strenght of cosine of frequency; blue - imaginary - strenght of sine of frequency; green - log1p of amplitude - just so it looks good to humans) - Nodes for FLOAT, CONDITIONING, LATENT, IMAGE, MASK, NOISE, AUDIO, VIDEO, MODEL, CLIP, VAE, SIGMAS and GUIDER - Vector Math: Support for List literals `[v1, v2, ...]` and operations between lists/scalars/tensors - Custom functions `funcname(variable,variable,...)->expression;` they can be used in any later defined custom function or in expression. Shadowing inbuilt functions do not work. **Be careful with recursion. There is no stack limit. Got to 700 000 iterations before I got bored.** diff --git a/more_math/nodes.py b/more_math/nodes.py index 2c400ac..00c5a96 100644 --- a/more_math/nodes.py +++ b/more_math/nodes.py @@ -79,6 +79,55 @@ class FloatToIntNode(io.ComfyNode): def execute(cls, value): return (int(value),) +class BoolToIntNode(io.ComfyNode): + """ + Converts bool to int. + """ + + @classmethod + def define_schema(cls) -> io.Schema: + """ """ + return io.Schema( + node_id="mrmth_BoolToInt", + display_name="Bool -> Int", + category="More math", + inputs=[ + io.Boolean.Input(id="value", default=0), + ], + outputs=[ + io.Int.Output(), + ], + ) + + @classmethod + def execute(cls, value): + return (int(value),) + + +class IntToBoolNode(io.ComfyNode): + """ + Converts int to bool. + """ + + @classmethod + def define_schema(cls) -> io.Schema: + """ """ + return io.Schema( + node_id="mrmth_IntToBool", + category="More math", + display_name="Int -> bool", + inputs=[ + io.Int.Input(id="value", default=0.0), + ], + outputs=[ + io.Boolean.Output(), + ], + ) + + @classmethod + def execute(cls, value): + return (bool(value),) + class MoreMathExtension(ComfyExtension): def __init__(self): @@ -106,6 +155,8 @@ class MoreMathExtension(ComfyExtension): NoiseMathNodeOLD, IntToFloatNode, FloatToIntNode, + BoolToIntNode, + IntToBoolNode, AudioMathNodeOLD, VideoMathNode, VideoMathNodeOLD, @@ -114,7 +165,7 @@ class MoreMathExtension(ComfyExtension): SigmasMathNode, GuiderMathNode, NoiseMathNode, - AudioMathNode + AudioMathNode, ]