@@ -26,9 +26,10 @@ SOFTWARE.
2626Small portable arbitrary-precision integer arithmetic library in pure Lua for
2727computing with large integers.
2828
29- Different from most arbitrary precision integer libraries in pure Lua out there this one
29+ Different from most arbitrary- precision integer libraries in pure Lua out there this one
3030uses an array of lua integers as underlying data-type in its implementation instead of
31- using strings or large tables, so regarding that aspect this library should be more efficient.
31+ using strings or large tables, this make it efficient for working with fixed width integers
32+ and to make bitwise operations.
3233
3334## Design goals
3435
@@ -40,17 +41,17 @@ integer overflow warps around,
4041signed integers are implemented using two-complement arithmetic rules,
4142integer division operations rounds towards minus infinity,
4243any mixed operations with float numbers promotes the value to a float,
43- and the usual division/power operation always promote to floats.
44+ and the usual division/power operation always promotes to floats.
4445
4546The library is designed to be possible to work with only unsigned integer arithmetic
4647when using the proper methods.
4748
4849All the lua arithmetic operators (+, -, *, //, /, %) and bitwise operators (&, |, ~, <<, >>)
4950are implemented as metamethods.
5051
51- The integer size must be fixed in advance and the library is designed to be efficient only when
52+ The integer size must be fixed in advance and the library is designed to be more efficient when
5253working with integers of sizes between 64-4096 bits. If you need to work with really huge numbers
53- without size restrictions then use other library. This choice has been made to have more efficiency
54+ without size restrictions then use another library. This choice has been made to have more efficiency
5455in that specific size range.
5556
5657## Usage
@@ -90,7 +91,7 @@ get the output from one of the following functions:
9091* @{bint.tobase} (convert to a string in any base)
9192* @{bint.__tostring} (convert to a string in base 10)
9293
93- To output very large integer with no loss you probably want to use @{bint.tobase}
94+ To output a very large integer with no loss you probably want to use @{bint.tobase}
9495or call `tostring` to get a string representation.
9596
9697## Precautions
@@ -102,14 +103,14 @@ however the user should take care in some situations:
102103* Don't mix integers and float operations if you want to work with integers only.
103104* Don't use the regular equal operator ('==') to compare values from this library,
104105unless you know in advance that both values are of the same primitive type,
105- otherwise it will always returns false, use @{bint.eq} to be safe.
106+ otherwise it will always return false, use @{bint.eq} to be safe.
106107* Don't pass fractional numbers to functions that an integer is expected
108+ * Don't mix operations between bint classes with different sizes as this is not supported.
107109as this will throw assertions.
108110* Remember that casting back to lua integers or numbers precision can be lost.
109111* For dividing while preserving integers use the @{bint.__idiv} (the '//' operator).
110112* For doing power operation preserving integers use the @{bint.ipow} function.
111- to the proper size you intend to work with, otherwise large integers may wraps around.
112- * Never mix operations between bint classes of different bit sizes
113+ * Configure the proper integer size you intend to work with, otherwise large integers may wrap around.
113114
114115]]
115116
322323--- Convert a bint to an unsigned integer.
323324-- Note that large unsigned integers may be represented as negatives in lua integers.
324325-- Note that lua cannot represent values larger than 64 bits,
325- -- in that case integer values wraps around.
326+ -- in that case integer values wrap around.
326327-- @param x A bint or a number to be converted into an unsigned integer.
327328-- @return An integer or nil in case the input cannot be represented by an integer.
328329-- @see bint.tointeger
341342--- Convert a bint to a signed integer.
342343-- It works by taking absolute values then applying the sign bit in case needed.
343344-- Note that lua cannot represent values larger than 64 bits,
344- -- in that case integer values wraps around.
345+ -- in that case integer values wrap around.
345346-- @param x A bint or value to be converted into an unsigned integer.
346347-- @return An integer or nil in case the input cannot be represented by an integer.
347348-- @see bint.touinteger
@@ -369,7 +370,7 @@ local function bint_assert_tointeger(x)
369370end
370371
371372--- Convert a bint to a lua float in case integer would wrap around or lua integer otherwise.
372- -- Different from @{bint.tointeger} the operation does not wraps around integers,
373+ -- Different from @{bint.tointeger} the operation does not wrap around integers,
373374-- but digits precision are lost in the process of converting to a float.
374375-- @param x A bint or value to be converted into a lua number.
375376-- @return A lua number or nil in case the input cannot be represented by a number.
398399-- @param x The bint to be converted from.
399400-- @param [opt] base Base to be represented, defaults to 10.
400401-- Must be at least 2 and at most 36.
401- -- @param [opt] unsigned Whether to output as unsigned integer.
402+ -- @param [opt] unsigned Whether to output as an unsigned integer.
402403-- Defaults to false for base 10 and true for others.
403404-- When unsigned is false the symbol '-' is prepended in negative values.
404405-- @return A string representing the input.
@@ -536,7 +537,7 @@ local function bint_assert_convert(x)
536537end
537538
538539--- Convert a value to a bint if possible otherwise to a lua number.
539- -- Useful to prepare values that you are unsure if its going to be a integer or float.
540+ -- Useful to prepare values that you are unsure if it's going to be an integer or float.
540541-- @param x A value to be converted (string, number or another bint).
541542-- @param [opt] clone A boolean that tells if a new bint reference should be returned.
542543-- Defaults to false.
@@ -836,8 +837,8 @@ function bint.abs(x)
836837 end
837838end
838839
839- --- Take floor of a number considering bints.
840- -- @param x A bint or a lua number to perform the floor.
840+ --- Take the floor of a number considering bints.
841+ -- @param x A bint or a lua number to perform the floor operation .
841842function bint .floor (x )
842843 if isbint (x ) then
843844 return bint .new (x )
@@ -847,7 +848,7 @@ function bint.floor(x)
847848end
848849
849850--- Take ceil of a number considering bints.
850- -- @param x A bint or a lua number to perform the ceil.
851+ -- @param x A bint or a lua number to perform the ceil operation .
851852function bint .ceil (x )
852853 if isbint (x ) then
853854 return bint .new (x )
@@ -994,7 +995,7 @@ function bint:_sub(y)
994995end
995996
996997--- Subtract two numbers considering bints.
997- -- @param x A bint or a lua number to be subtract from.
998+ -- @param x A bint or a lua number to be subtracted from.
998999-- @param y A bint or a lua number to subtract.
9991000function bint .__sub (x , y )
10001001 local ix , iy = bint .tobint (x ), bint .tobint (y )
@@ -1265,7 +1266,7 @@ function bint.__idiv(x, y)
12651266end
12661267
12671268--- Perform division between two numbers considering bints.
1268- -- This always cast inputs to floats, for integer division only use @{bint.__idiv}.
1269+ -- This always casts inputs to floats, for integer division only use @{bint.__idiv}.
12691270-- @param x The numerator, a bint or lua number.
12701271-- @param y The denominator, a bint or lua number.
12711272-- @return The quotient, a lua number.
@@ -1286,7 +1287,7 @@ function bint.__mod(x, y)
12861287end
12871288
12881289--- Perform integer power between two integers considering bints.
1289- -- If y is negative then pow is performed as unsigned integers .
1290+ -- If y is negative then pow is performed as an unsigned integer .
12901291-- @param x The base, an integer.
12911292-- @param y The exponent, an integer.
12921293-- @return The result of the pow operation, a bint.
@@ -1344,7 +1345,7 @@ function bint.upowmod(x, y, m)
13441345end
13451346
13461347--- Perform numeric power between two numbers considering bints.
1347- -- This always cast inputs to floats, for integer power only use @{bint.ipow}.
1348+ -- This always casts inputs to floats, for integer power only use @{bint.ipow}.
13481349-- @param x The base, a bint or lua number.
13491350-- @param y The exponent, a bint or lua number.
13501351-- @return The result of the pow operation, a lua number.
@@ -1479,12 +1480,12 @@ function bint.__bnot(x)
14791480 return y
14801481end
14811482
1482- --- Negate a bint (in-place). This apply effectively apply two's complements.
1483+ --- Negate a bint (in-place). This effectively applies two's complements.
14831484function bint :_unm ()
14841485 return self :_bnot ():_inc ()
14851486end
14861487
1487- --- Negate a bint. This apply effectively apply two's complements.
1488+ --- Negate a bint. This effectively applies two's complements.
14881489-- @param x A bint to perform negation.
14891490function bint .__unm (x )
14901491 return (~x ):_inc ()
0 commit comments