Giter VIP home page Giter VIP logo

lua-extensions's Introduction

About Me

I do random things from time to time.

You'll probably find me programming.

My current go to languages: Lua and Zig

My Site

truemedian.me

Github

Top Languages Github Stats

lua-extensions's People

Contributors

bilal2453 avatar riskozoslovenska avatar tohrumkdm avatar truemedian avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

lua-extensions's Issues

define the exact behavior of table.shift

What should happen when a negative count is passed? Currently it is vague to me, and the behavior I may expect is not what happens. Instead the current behavior is:

local tbl = {1, 2, 3, 4, 5}
table.shift(tbl, 4, -2)

outputs:

{
  [1] = 1,
  [2] = 4,
  [3] = 5,
  [4] = 4,
  [5] = 5,
}

Or an error should be raised for those inputs if not documented.

math: approxeqabs failing

approxeqabs(1 + (1 * math.epsilon), 1) is returning false when it seems like it should be true. See the equivalent Zig test.

Haven't looked into this one just yet but it seems fairly identical to the Zig code, assuming @fabs is doing what I am expecting it does.

P.S. the comparison in approxeqabs should be <= not < as well.

Oops, seems like that < comparison was actually the cause, I thought it wasn't because I ran the wrong test.

table methods operating on array portion

A note should be added about the behavior of functions that operate on the array portion of a table that has holes, either defining a specific behavior or (since all of them use ipairs or #) document that the behavior is undefined/follows that of ipairs.

Those functions are table.reduce, table.reverse, table.join, table.randomipair and table.randomvalue.

math.approxeqrel not accurate enough

Trying to do math.approxeqrel(math.root(-64, 3), -4) yields false.

On line 142 it seems like it was suppose to be:

tolerance = tolerance or math.sqrt(ext_math.epsilon)

On line 149 shouldn't the comparison be <=, just in case?

Printing out the left and right half of the comparison with the above example yields:
math.abs(a - b): 4.4408920985006e-16
math.max(a, b) * tolerance: -8.8817841970013e-16

I suppose line 149 should be:

return math.abs(a - b) <= math.abs(math.max(a, b)) * tolerance

which seems to work, in this example at least

string.cjust will overshoot with multi-byte pattern

It is documented in string.cjust that it will not overshoot final_len when given a multi-byte pattern, although that is incorrect.

print(string.cjust("foo", 4, '123')) ---> "foo123"

The previous code will result in a string that has the length 6, while the provided final_len was 4. Is that not what the documentation meant?

table.reverse when dest = tbl

It should be documented what behavior to expect if dest was the same table as the tbl argument, such as in:

local tbl = {1, 2, 3}
table.reverse(tbl, tbl)

Currently, it seems like it isn't supported, so that should be documented.

table: A sort function which returns the input table

The standard table.sort() sorts a table in-place and doesn't return anything, which is an annoyance whenever the table needs to also be modified in some way either prior to or after sorting. For example, compare the following:

local function sortedKeys(tbl)
    local keys = table.keys(tbl)
    table.sort(keys)
    return keys
end

-- vs

local function sortedKeys(tbl)
    return table.sort(table.keys(tbl))
end

Not only is the second snippet considerably shorter, but it is also slightly easier to read. I come across these kinds of use cases fairly often and so I think it's a worthwhile issue to address.

Overriding table.sort isn't a good idea, but I'm lost on as to what to name a function that would have the same behaviour as the stock one but returns the sorted table. table.sort2 could work may be confusing, and table.sorted implies a copy.

math: sign with unexpected inputs

  • sign should probably do type checking so it does not return 0 on say strings.

  • sign should check for NaN so it does not return 0 when it is not actually that.

Could be simply made:

function ext_math.sign(n)
	if n > 0 then
		return 1
	elseif n < 0 then
		return -1
	elseif n == 0 then
		return 0
	end
end

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.