diff --git a/compiler/res/prog8lib/floats_functions.p8 b/compiler/res/prog8lib/floats_functions.p8 index 3cddb66c4..052ff3adb 100644 --- a/compiler/res/prog8lib/floats_functions.p8 +++ b/compiler/res/prog8lib/floats_functions.p8 @@ -39,18 +39,6 @@ sub pow(float value, float power) -> float { }} } -sub fabs(float value) -> float { - %asm {{ - stx P8ZP_SCRATCH_REG - lda #value - jsr MOVFM - jsr ABS - ldx P8ZP_SCRATCH_REG - rts - }} -} - sub sin(float angle) -> float { %asm {{ lda # float { }} } -sub sqrtf(float value) -> float { - %asm {{ - lda #value - jsr MOVFM - stx P8ZP_SCRATCH_REG - jsr SQR - ldx P8ZP_SCRATCH_REG - rts - }} -} - sub rad(float angle) -> float { ; -- convert degrees to radians (d * pi / 180) %asm {{ diff --git a/compiler/res/prog8lib/virtual/floats.p8 b/compiler/res/prog8lib/virtual/floats.p8 index 2ac43e318..5f8a61965 100644 --- a/compiler/res/prog8lib/virtual/floats.p8 +++ b/compiler/res/prog8lib/virtual/floats.p8 @@ -25,14 +25,6 @@ sub pow(float value, float power) -> float { }} } -sub fabs(float value) -> float { - %ir {{ - loadm.f fr0,floats.fabs.value - fabs.f fr0,fr0 - returnr.f fr0 - }} -} - sub sin(float angle) -> float { %ir {{ loadm.f fr0,floats.sin.angle @@ -81,14 +73,6 @@ sub log2(float value) -> float { }} } -sub sqrtf(float value) -> float { - %ir {{ - loadm.f fr0,floats.sqrtf.value - sqrt.f fr0,fr0 - returnr.f fr0 - }} -} - sub rad(float angle) -> float { ; -- convert degrees to radians (d * pi / 180) return angle * PI / 180.0 diff --git a/compiler/test/arithmetic/div.p8 b/compiler/test/arithmetic/div.p8 index 3fc9ccb71..6478d415f 100644 --- a/compiler/test/arithmetic/div.p8 +++ b/compiler/test/arithmetic/div.p8 @@ -87,7 +87,7 @@ main { sub div_float(float a1, float a2, float c) { float r = a1/a2 - if floats.fabs(r-c)<0.00001 + if abs(r-c)<0.00001 txt.print(" ok ") else txt.print("err! ") diff --git a/compiler/test/arithmetic/minus.p8 b/compiler/test/arithmetic/minus.p8 index 0d76137d5..8bcf82b70 100644 --- a/compiler/test/arithmetic/minus.p8 +++ b/compiler/test/arithmetic/minus.p8 @@ -98,7 +98,7 @@ main { sub minus_float(float a1, float a2, float c) { float r = a1-a2 - if floats.fabs(r-c)<0.00001 + if abs(r-c)<0.00001 txt.print(" ok ") else { txt.print("err! ") diff --git a/compiler/test/arithmetic/mult.p8 b/compiler/test/arithmetic/mult.p8 index 2d735ceab..b3d025a03 100644 --- a/compiler/test/arithmetic/mult.p8 +++ b/compiler/test/arithmetic/mult.p8 @@ -89,7 +89,7 @@ main { sub mul_float(float a1, float a2, float c) { float r = a1*a2 - if floats.fabs(r-c)<0.00001 + if abs(r-c)<0.00001 txt.print(" ok ") else txt.print("err! ") diff --git a/compiler/test/arithmetic/plus.p8 b/compiler/test/arithmetic/plus.p8 index 503220ed1..e3addcf3f 100644 --- a/compiler/test/arithmetic/plus.p8 +++ b/compiler/test/arithmetic/plus.p8 @@ -93,7 +93,7 @@ main { sub plus_float(float a1, float a2, float c) { float r = a1+a2 - if floats.fabs(r-c)<0.00001 + if abs(r-c)<0.00001 txt.print(" ok ") else txt.print("err! ") diff --git a/docs/source/libraries.rst b/docs/source/libraries.rst index d8120705e..13b4d09dc 100644 --- a/docs/source/libraries.rst +++ b/docs/source/libraries.rst @@ -246,9 +246,6 @@ point variables. This includes ``print_f``, the routine used to print floating ``deg (x)`` Radians to degrees. -``fabs (x)`` - Returns the absolute value of x. Deprecated; just use the builtin ``abs(x)`` function instead. - ``floor (x)`` Rounds the floating point down to an integer towards minus infinity. @@ -278,10 +275,6 @@ point variables. This includes ``print_f``, the routine used to print floating If you want a fast integer sine, have a look at examples/cx16/sincos.p8 that contains various lookup tables generated by the 64tass assembler. -``sqrtf (x)`` - Floating point Square root. Deprecated; just use the ``sqrt (x)`` builtin fuction instead. - To do the reverse, squaring a floating point number, just write ``x*x``. - ``tan (x)`` Tangent. diff --git a/docs/source/todo.rst b/docs/source/todo.rst index 4d89139c6..9b9d6e045 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -5,8 +5,8 @@ For 9.0 major changes ^^^^^^^^^^^^^^^^^^^^^ - DONE: added 'cbm' block in the syslib module that now contains all CBM compatible kernal routines and variables - DONE: added min() max() builtin functions -- DONE: rename sqrt16() to just sqrt(), make it accept multiple numeric types. Renamed floats.sqrt() to floats.sqrtf() but you can just use sqrt() -- DONE: abs() now supports multiple datatypes including float. No need to use floats.fabs() anymore. +- DONE: rename sqrt16() to just sqrt(), make it accept multiple numeric types including float. Removed floats.sqrt(). +- DONE: abs() now supports multiple datatypes including float. Removed floats.fabs(). - DONE: divmod() now supports multiple datatypes. divmodw() has been removed. - DONE: cx16diskio module merged into diskio (which got specialized for commander x16 target). load() and load_raw() with extra ram bank parameter are gone. - DONE: drivenumber parameter removed from all routines in diskio module. The drive to work on is now simply stored as a diskio.drivenumber variable, which defaults to 8. diff --git a/docs/source/upgrading8.rst b/docs/source/upgrading8.rst index 6d5bcf906..2aa70f10e 100644 --- a/docs/source/upgrading8.rst +++ b/docs/source/upgrading8.rst @@ -44,11 +44,17 @@ For loops now do a check at the start and skip the whole loop if the start value This is the normal behavior of most other programming languages. -For 9.0 major changes -^^^^^^^^^^^^^^^^^^^^^ -- DONE: added min() max() builtin functions -- DONE: rename sqrt16() to just sqrt(), make it accept multiple numeric types. Renamed floats.sqrt() to floats.sqrtf() but you can just use sqrt() -- DONE: abs() now supports multiple datatypes including float. No need to use floats.fabs() anymore. -- DONE: divmod() now supports multiple datatypes. divmodw() has been removed. +divmod(), sqrt() and abs() builtin functions accept multiple data types +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +- ``divmodw()`` doesn't exist anymore, just use ``divmod()``. +- ``sqrt16()`` doesn't exist anymore, just use ``sqrt()``. +- ``floats.fabs()`` and ``floats.sqrt()`` don't exist anymore, just use ``abs()`` and ``sqrt()`` they now accept floating point as well. +min() and max() are new builtin functions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +If you used symbols named ``min`` or ``max`` you have to choose a new name as these are now +reserved for the two new builtin functions. +Code that uses an if statement and a comparison to determine the greater or lesser of two values, +can now be optimized by just using one of these new builtin functions. + diff --git a/examples/test.p8 b/examples/test.p8 index e7c9c21d1..19c958343 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -1,18 +1,21 @@ +%import floats %import textio %zeropage basicsafe main { sub start() { - word vfrom = $1000 - word vto = $1000 + word ww = -1234 + float fl = 123.34 + byte bb = -99 - word xx - for xx in vfrom to vto step -1 { - txt.print_w(xx) - txt.spc() - } -skip: + txt.print_w(abs(ww)) + txt.nl() + txt.print_b(abs(bb)) + txt.nl() + floats.print_f(abs(fl)) + txt.nl() + floats.print_f(sqrt(fl)) txt.nl() } }