Giter Site home page Giter Site logo

int's Introduction

int

https://github.com/SupTan85/int This Project is math and calculate for large data in Lua.
this module is in beta! some function/feature won't work on very large data.
reason why this module name is "int"? because in this module alway use integer to calculate math!
Verified: Lua5.3 Lua5.4

Feature

  • Calculate

    • addition +
    • subtraction -
    • multiplication *
    • division \, \\
    • modulo %
    • power ^
    • sqrt
  • Equation

    • equal
    • less than
    • more than
  • Other

    • tostring
    • tonumber
    • sign
    • max
    • min
    • abs
    • In Natural logarithm
    • fact Factorial function
    • exp Exponential function
    • floor
    • cround
    • integerlen INTEGER LEN
    • fractionlen FRACTION LEN
    • fdigitlen INTEGER LEN + FRACTION LEN

and more...

How to use

Require a module with require function in Lua

local int = require("int")

Use this module you should to make a new object

local int = require("int")

local x = int.new("13") -- input can be a number or string! *recommend to use string*

print(x) -- output: "13"

Use Calculation operators to calculate math.

Note: only operator that in support

-- require a module
local int = require("int")

-- build a new int object
local x = int.new("20")
local y = int.new("10")

print(x + y) -- output: 30

Note: in version 148 or latest version. you can calculate int object with number without using int.new

-- require a module
local int = require("int")

-- build a new int object
local x = int.new("2")

print(x + 2) -- output: 4

Note: in version 163 or latest version. you can call function with int object without using int

-- require a module
local int = require("int")

-- build a new int object
local x, y = int.new("5"), 2

-- if "x" is more then "y"
if x:more(y) then
    print(x:tostring().." is more then "..y)
end

Recommend: some equation operators won't work with other type, but alway work with int object.

DO NOT DO LIKE THIS:

local int = require("int")
local x = int.new("5")

-- DO NOT DO LIKE THIS:
print(x > 2) -- error

BUT DO LIKE THIS:

local int = require("int")
local x = int.new("5")

-- DO LIKE THIS:
print(x:more(2)) -- output: true

Design

This inside of int object, this is a number "101" also you use tonumber function to convert to number.

local example_int_table = {
    -- digit --
    [1] = 1, -- this a digit block
    [0] = 0,
    [-1] = 1,

    -- data --
    sign = "+",

    _dlen = -1, -- digit of fraction *this for calculate a fraction* **DO NOT CHANGE. HAVE LIMIT!!**
    _size = 1 -- mean per size of block *just maximum digit per value in the digit block* **DO NOT CHANGE. HAVE LIMIT!!**
}

Function

all function is in version: build 180

  • module function
    • int.new
    • int.cnew
    • int.tostring
    • int.tonumber
    • int.equal
    • int.less
    • int.more
    • int.eqless
    • int.eqmore
    • int.abs
    • int.fact
    • int.In
    • int.exp
    • int.sqrt
    • int.pow
    • int.ceil
    • int.fdigitlen
    • int.floor
    • int.cround
    • int.fmod
    • int.fractionlen
    • int.integerlen
    • int.max
    • int.min
    • int.modf
    • int.sign

Example to call a function:

-- require a module.
local int = require("int")

-- build int object.
local x = int.new("14.695")

-- using a custom floor function.
print(int.floor(x, 2)) -- output: 14.69

  • methods
    • abs
    • fact
    • In
    • exp
    • sqrt
    • pow
    • ceil
    • eqless
    • eqmore
    • equal
    • fdigitlen
    • floor
    • cround
    • fmod
    • fractionlen
    • integerlen
    • less
    • max
    • min
    • modf
    • more
    • sign
    • tonumber
    • tostring

Example to call a function:

-- require a module.
local int = require("int")

-- build int object.
local x = int.new("14.695")

-- using a custom floor function.
print(x:floor(2)) -- output: 14.69

Limit

  • Maximum digit of integer is 9223372036854775806

    • Set _size to 9 maximum digit of integer is 83010348331692982254 (9223372036854775806 * 9)
  • Maximum digit of fraction is 9223372036854775808

    • Set _size to 9 maximum fraction of integer is 83010348331692982263 (9223372036854775808 * 9)

end

int's People

Contributors

narngisa avatar suptan85 avatar

Forkers

narngisa

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.