Skip to content

Fractions Type for V2 #32

@thiagomvas

Description

@thiagomvas

Summary

Add a Fraction type for exact rational number representation, avoiding floating-point errors.

Motivation

  • Floating-point arithmetic introduces rounding errors.
  • Useful for exact calculations in number theory, algebra, and symbolic math.
  • Enables precise fraction representation (e.g., 1/3, 5/8).

Proposed API

  • Fraction(int numerator, int denominator)
  • Arithmetic: +, -, *, /
  • Reduction to simplest form
  • Conversions: double, decimal, string
  • Comparisons: ==, <, >, <=, >=

Example Usage

var f1 = new Fraction(1, 3);
var f2 = new Fraction(2, 3);
var sum = f1 + f2; // 1/1
var product = f1 * f2; // 2/9

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions