coalton-lang / coalton

Coalton is an efficient, statically typed functional programming language that supercharges Common Lisp.

Home Page:https://coalton-lang.github.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Big-Float constants `ee` and `pi` don't change to match precision.

Izaakwltn opened this issue · comments

These variables are locked in with the initial big-float precision, and don't adjust as precision changes.

Initial precision is 53 bits so they're basically locked in as Double-Floats.

note: this is only an issue with the MPFR version of the library. The portable version handles this fine.

I've been thinking about this bug, and thought of a couple quick but potentially janky approaches for fixing it.

  • Every time precision is set, redefine Trigonometric Big-Float and Exponentiable Big-Float, which will automatically update the definition of pi and ee respectively. This could be kept in separate functions like reset-bf-constants or set-precision-and-constants. Bubble-gum and paperclip approach.

    • Note: Is it possible to redefine one member of a type class or does every redefinition have to be applied as a whole?
  • Convert Big-Float to MPFR-Float and make a new Big-Float type in the style of impl-default.lisp that uses MPFR-Floats instead of Dyadics. This is probably the nuclear option.

  • Simplifying the possibility above, give Big-Float two constructors that contain either an MPFR-Float object or a (Unit -> MPFR-Float) function:

(define-type Big-Float
  (BFValue MPFR-Float)
  (BFConst (Unit -> MPFR-Float))

Ignoring potential language changes, the last suggestion would be the right approach.