From e01d707cc31cff61f796cb6afb3e9c1275891fda Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sun, 24 May 2026 12:52:20 +0300 Subject: rpn: remove exported Number type alias MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit type Number = NumericValue was a legacy alias that created confusion — callers could use Number or NumericValue interchangeably. Removed the alias and updated: - NewNumber/NewNumberWithMetric return types: Number -> NumericValue - Comments referencing Number now say NumericValue The alias added no value since Number was never used as a distinct type anywhere in the codebase. --- internal/rpn/number.go | 15 +++++++++------ internal/rpn/operations_constants.go | 2 +- internal/rpn/operations_variables.go | 2 +- internal/rpn/variables.go | 2 +- 4 files changed, 12 insertions(+), 9 deletions(-) (limited to 'internal') diff --git a/internal/rpn/number.go b/internal/rpn/number.go index a188edf..de6fa93 100644 --- a/internal/rpn/number.go +++ b/internal/rpn/number.go @@ -44,8 +44,11 @@ type NumericValue interface { SetMetric(m *Metric) NumericValue } -// Number is the legacy alias for NumericValue, kept for backward compatibility. -type Number = NumericValue +// NumericValue is the interface for numeric values (float64 or *big.Rat). +// It extends StackValue with metric operations. +// +// Note: type Number was a legacy alias for NumericValue, removed to avoid +// confusion between the alias and the concrete type. // Compile-time interface satisfaction checks. var _ StackValue = (*Float)(nil) @@ -55,20 +58,20 @@ var _ NumericValue = (*Rat)(nil) var _ StackValue = (*StringNum)(nil) var _ StackValue = (*Symbol)(nil) -// NewNumber creates a Number from a float64 value with the given mode. +// NewNumber creates a NumericValue from a float64 value with the given mode. // The actual type depends on the current calculation mode (Float or Rat). // The metric defaults to Cool (unitless). -func NewNumber(value float64, mode CalculationMode) Number { +func NewNumber(value float64, mode CalculationMode) NumericValue { if mode == RationalMode { return NewRat(value) } return NewFloat(value) } -// NewNumberWithMetric creates a Number from a float64 value with an explicit metric. +// NewNumberWithMetric creates a NumericValue from a float64 value with an explicit metric. // The actual type depends on the current calculation mode (Float or Rat). // If metric is nil, defaults to Cool. -func NewNumberWithMetric(value float64, mode CalculationMode, metric *Metric) Number { +func NewNumberWithMetric(value float64, mode CalculationMode, metric *Metric) NumericValue { if metric == nil { metric = GetCoolMetric() } diff --git a/internal/rpn/operations_constants.go b/internal/rpn/operations_constants.go index 7fbd4c9..8cb0366 100644 --- a/internal/rpn/operations_constants.go +++ b/internal/rpn/operations_constants.go @@ -19,7 +19,7 @@ func (o *Operations) ListConstants() (string, error) { } sb.WriteString(info.Name) sb.WriteString(" = ") - // Use Number interface for consistent formatting + // Use NumericValue interface for consistent formatting num := NewNumber(info.Value, FloatMode) sb.WriteString(num.String()) } diff --git a/internal/rpn/operations_variables.go b/internal/rpn/operations_variables.go index fb340ec..49cab57 100644 --- a/internal/rpn/operations_variables.go +++ b/internal/rpn/operations_variables.go @@ -25,7 +25,7 @@ func (o *Operations) AssignVariable(stack *Stack, name string) error { return err } - // Convert Number to float64 for variable storage + // Convert NumericValue to float64 for variable storage valF, err := toFloat64(val, "assigning variable") if err != nil { return err diff --git a/internal/rpn/variables.go b/internal/rpn/variables.go index 56eb1ae..ac04cf1 100644 --- a/internal/rpn/variables.go +++ b/internal/rpn/variables.go @@ -185,7 +185,7 @@ func (v *Variables) formatVariablesUnsafe() string { if i > 0 { sb.WriteString("\n") } - // Use Number interface for consistent formatting + // Use NumericValue interface for consistent formatting num := NewNumber(info.Value, FloatMode) sb.WriteString(info.Name) sb.WriteString(" = ") -- cgit v1.2.3