From 5ac9c75521c3af2e9d74c9b1a65cce50cee12640 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Wed, 17 Apr 2024 20:03:36 +0200 Subject: [PATCH] docs of new floats routines and added them to VM target too --- compiler/res/prog8lib/virtual/floats.p8 | 14 ++++++++++++++ docs/source/libraries.rst | 13 +++++++++++++ 2 files changed, 27 insertions(+) diff --git a/compiler/res/prog8lib/virtual/floats.p8 b/compiler/res/prog8lib/virtual/floats.p8 index b74c30c9f..882e4295b 100644 --- a/compiler/res/prog8lib/virtual/floats.p8 +++ b/compiler/res/prog8lib/virtual/floats.p8 @@ -80,6 +80,20 @@ sub atan(float value) -> float { }} } +; two-argument arctangent that returns an angle in the correct quadrant +; for the signs of x and y, normalized to the range [0, 2π] +sub atan2(float y, float x) -> float { + float atn = atan(y / x) + if x < 0 atn += π + if atn < 0 atn += 2*π + return atn +} + +; reciprocal functions +sub secant(float value) -> float { return 1.0 / cos(value) } +sub csc(float value) -> float { return 1.0 / sin(value) } +sub cot(float value) -> float { return 1.0 / tan(value) } + sub ln(float value) -> float { %ir {{ loadm.f fr0,floats.ln.value diff --git a/docs/source/libraries.rst b/docs/source/libraries.rst index 669288a70..21f9f1e2f 100644 --- a/docs/source/libraries.rst +++ b/docs/source/libraries.rst @@ -382,12 +382,22 @@ point variables. This includes ``print_f``, the routine used to print floating ``atan (x)`` Arctangent. +``atan2 (y, x)`` + Two-argument arctangent that returns an angle in the correct quadrant + for the signs of x and y, normalized to the range [0, 2π] + ``ceil (x)`` Rounds the floating point up to an integer towards positive infinity. ``cos (x)`` Cosine. +``cot (x)`` + Cotangent: 1/tan(x) + +``csc (x)`` + Cosecant: 1/sin(x) + ``deg (x)`` Radians to degrees. @@ -426,6 +436,9 @@ point variables. This includes ``print_f``, the routine used to print floating ``sin (x)`` Sine. +``secant (x)`` + Secant: 1/cos(x) + ``tan (x)`` Tangent.