Giter Site home page Giter Site logo

Comments (4)

agentzh avatar agentzh commented on August 26, 2024 1

@theoneqq Better not in that redis library. It might be a good idea to simply change the LuaJIT's tostring() method. The LL suffix is indeed not very helpful usually.

from luajit2.

agentzh avatar agentzh commented on August 26, 2024

10^14 already exceeds a 32-bit integer's range and LuaJIT will store it as a double-precision floating point number. You need 64-bit integers, in LuaJIT, should use cdata instead. Like this:

$ resty -e 'print(1234567901234567890LL)'
1234567901234567890LL

Or to remove the LL suffix:

$ resty -e 'print(string.sub(tostring(1234567901234567890LL), 0, -3))'
1234567901234567890

If you do no want to do arithmetic on the 64-bit integer values, then you should just use strings from the very beginning instead of using Lua numbers or Lua cdata objects.

BTW, the code you quoted is from minilua (you have a type in your message, not minlua). The minilua is only used when building the LuaJIT itself. It no longer exists in the final installed LuaJIT tree.

from luajit2.

theoneqq avatar theoneqq commented on August 26, 2024

openresty/bundle/lua-resty-redis/lib/resty/redis.lua

local function _gen_req(args)
    local nargs = #args

    local req = new_tab(nargs * 5 + 1, 0)
    req[1] = "*" .. nargs .. "\r\n"
    local nbits = 2

    for i = 1, nargs do
        local arg = args[i]
        if type(arg) ~= "string" then
            arg = tostring(arg)
        end

        req[nbits] = "$"
        req[nbits + 1] = #arg
        req[nbits + 2] = "\r\n"
        req[nbits + 3] = arg
        req[nbits + 4] = "\r\n"

        nbits = nbits + 5
    end

    -- it is much faster to do string concatenation on the C land
    -- in real world (large number of strings in the Lua VM)
    return req
end

Thanks, I got it. I wander if I can modify above tostring method, instead of to distinguish common number and big number.

from luajit2.

theoneqq avatar theoneqq commented on August 26, 2024

It's really a good idea, I will try

from luajit2.

Related Issues (20)

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.