nanos-world / issues

Issue Tracker for nanos world
9 stars 1 forks source link

Standard math functions not implemented. #1005

Closed Deviatt closed 3 months ago

Deviatt commented 3 months ago

Prerequisites

Your Environment

Description

It's possible that these functions were removed due to inattention or developer discretion. I think you need to restore the integrity of the standard Lua library.

The frexp/ldexp functions for those who might need it:

local floor, log, abs = math.floor, math.log, math.abs
function math.frexp(x)
    if (x == 0) then return 0.0, 0 end
    local e = floor(log(abs(x), 2))
    x = x / (1 << e)

    if (abs(x) >= 1) then
        x, e = x * .5, e + 1
    end

    return x, e
end

function math.ldexp(m, e)
    return m * (1 << e)
end

Steps to reproduce the behavior

  1. Run Console.Log(NanosTable.Dump(math))

Expected behavior

These functions should exist by default, as they are part of the standard Lua library. This may seem useless to some, but it should be implemented by default!

Actual behavior

Nanos Lua image LuaPUC 5.4.2 image

Timmy-the-nobody commented 3 months ago

These functions were deprecated in lua 5.3 https://www.lua.org/manual/5.3/manual.html

The following functions were deprecated in the mathematical library: atan2, cosh, sinh, tanh, pow, frexp, and ldexp. You can replace math.pow(x,y) with x^y; you can replace math.atan2 with math.atan, which now accepts one or two arguments; you can replace math.ldexp(x,exp) with x * 2.0^exp. For the other operations, you can either use an external library or implement them in Lua.

Deviatt commented 3 months ago

Эти функции устарели в lua 5.3 https://www.lua.org/manual/5.3/manual.html

В математической библиотеке объявлены устаревшими следующие функции: atan2, cosh, sinh, tanh, pow, frexp и ldexp. Вы можете заменить math.pow(x,y) на x^y; Вы можете заменить math.atan2 на math.atan, который теперь принимает один или два аргумента; Вы можете заменить math.ldexp(x,exp) на x * 2.0^exp. Для остальных операций можно либо использовать внешнюю библиотеку, либо реализовать их на Lua.

Oh, thank you. I forgot that my build is backwards compatible. Don't you think you should do the same?

Timmy-the-nobody commented 3 months ago

I think we should stick to the current state and let scripters add these functions to their project if necessary, so the lua documentation of the version used by the game will be 1:1 with what will be available on the game