# some ideas by u/DaVinci103 # MIT License, Copyright (c) 2024 Marvin Borner :import std/Logic . :import std/Combinator . :import std/Pair . :import std/Math/Rational Q :import std/Math N # a Real is just a Number → Rational! # converts a balanced ternary number to a real number number→real [[Q.number→rational 1]] ⧗ Number → Real :test (number→real (+5)) ((+5.0r)) # returns true if two real numbers are equal approximately approx-eq? [[[Q.eq? (1 2) (0 2)]]] ⧗ Number → Real → Real → Boolean # TODO: bigger value?? …≈?… approx-eq? (+100) # returns true if a real number is greater than another gt? [[[Q.gt? (1 2) (0 2)]]] ⧗ Number → Real → Real → Boolean …>?… gt? # returns true if a real number is less than another lt? [[[Q.lt? (1 2) (0 2)]]] ⧗ Number → Real → Real → Boolean …?‣ positive? # returns true if a real number is negative negative? [\(lt? 0) (+0.0r)] ⧗ Number → Real → Boolean ?0 (+1.0q) (-1.0q)) (π/2 1) conj-atan atan* [Q.div (+1.0q) 1] 1 fallback Q.lt? Q.|0 (+1.0) (atan* [1] 1) normal # 2-argument arctan atan2 [[[[[go]] (2 0) (1 0)]]] ⧗ Real → Real → Real go Q.add a (Q.mul b (Q.add c d)) z (+0.0q) a Q.=?0 z (atan [Q.div 2 1] 2) b Q.sub (+1.0q) (Q.