GcdPolicy

it.grypho.scala.leonardo.core.GcdPolicy
enum GcdPolicy

When a _Rational reduces itself to lowest terms.

The policy changes representation only, never value: 2/6 and 1/3 are the same rational, and _Rational.equals compares by cross-multiplication precisely so that the choice stays invisible to callers. What it does change is cost — gcd is the expensive step of rational arithmetic, while skipping it roughly doubles operand size per operation — which is why it is a measured decision rather than a guess.

Selected per call site rather than through Environment, following the simplifyLogic(e, symmetric, semantics) precedent: nothing in this tier goes through eval yet, so an environment field would be unread. It moves into Environment with the tier-1 AST integration, alongside the working precision.

Attributes

Graph
Supertypes
trait Enum
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Members list

Type members

Enum entries

case Eager extends GcdPolicy

Reduce on every construction — what spire's Rational does, and the conventional choice. Pays one gcd per operation to keep operands minimal.

Reduce on every construction — what spire's Rational does, and the conventional choice. Pays one gcd per operation to keep operands minimal.

Attributes

case Lazy extends GcdPolicy

Never reduce. Relies on the bounded-denominator re-approximation (_Rational.approximate) to cap growth instead of on gcd.

Never reduce. Relies on the bounded-denominator re-approximation (_Rational.approximate) to cap growth instead of on gcd.

Attributes

final case class Threshold(maxBits: Int)

Reduce only once an operand grows past maxBits bits — the middle policy, and in production rational libraries usually the one that wins.

Reduce only once an operand grows past maxBits bits — the middle policy, and in production rational libraries usually the one that wins.

Value parameters

maxBits

bit-length above which either term triggers a reduction

Attributes