← Library Predicate Deterministic

BetweenFloatOp

Returns true when Min ≤ Value ≤ Max (inclusive range check).

Inputs

Field Type Description
Value*float64Value to test
Min*float64Lower bound (inclusive)
Max*float64Upper bound (inclusive)

Outputs

Field Type Description
MatchboolTrue when Min ≤ Value ≤ Max

Typical Use Cases

  • Score banding into tiers
  • Range validation for numeric inputs
  • Tier classification after AIScoreOp

Complete Runnable Example

Checks whether a confidence score of 0.72 falls within the medium-confidence band of 0.5–0.9.

main.go
package main

import (
	"context"
	"encoding/json"
	"log"
	"os"
	"time"

	"github.com/akennis/sparsi-go/library"
	_ "github.com/akennis/dagor/operator/builtin"

	"github.com/panjf2000/ants/v2"
	"github.com/akennis/dagor"
	"github.com/akennis/dagor/graph"
)

func main() {
	score, lo, hi := 0.72, 0.5, 0.9
	library.RegisterConst("score_val", score)
	library.RegisterConst("lo_val", lo)
	library.RegisterConst("hi_val", hi)

	g, err := graph.NewBuilder("between_demo").
		Vertex("src_v").Op("score_val").Output("Result", "wire_v").
		Vertex("src_lo").Op("lo_val").Output("Result", "wire_lo").
		Vertex("src_hi").Op("hi_val").Output("Result", "wire_hi").
		Vertex("check").Op("BetweenFloatOp").
		Input("Value", "wire_v").
		Input("Min", "wire_lo").
		Input("Max", "wire_hi").
		Output("Match", "in_range").
		Build()
	if err != nil {
		log.Fatalf("build: %v", err)
	}

	pool, err := ants.NewPool(4)
	if err != nil {
		log.Fatalf("pool: %v", err)
	}
	defer pool.Release()

	eng, err := dagor.NewEngine(g, pool)
	if err != nil {
		log.Fatalf("engine: %v", err)
	}

	ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
	defer cancel()

	if err := eng.Run(ctx); err != nil {
		log.Fatalf("run: %v", err)
	}

	out := map[string]any{"score": score, "min": lo, "max": hi}
	if raw, ok := eng.GetOutput("in_range"); ok {
		out["in_range"] = *raw.(*bool)
	}
	enc := json.NewEncoder(os.Stdout)
	enc.SetIndent("", "  ")
	enc.Encode(out)
}