Commit Graph

141 Commits

Author SHA1 Message Date
Mamy André-Ratsimbazafy 195480d58a
passing compile-time bitwise tests (but not runtime :?) 2023-06-12 17:08:20 +07:00
Mamy André-Ratsimbazafy 777a84e9f5
Implement toHex/fromHex and fix `shl` 2023-06-12 17:08:20 +07:00
Mamy André-Ratsimbazafy 2ac1ee3f1e
Fix compiletime primitives to pass all bitwise tests except large shifts 2023-06-12 17:08:20 +07:00
Mamy André-Ratsimbazafy 7f6c588ce3
Passing addition tests (however simple bitwise ops crash the int128 VM ... during compilation) 2023-06-12 17:08:20 +07:00
Mamy André-Ratsimbazafy a0dec54c12
Implement multiplication 2023-06-12 17:08:20 +07:00
Mamy André-Ratsimbazafy 206ffa92cf
Implement multiprecision addition / substraction 2023-06-12 17:08:19 +07:00
Mamy André-Ratsimbazafy cbbffe4e9c
reimplement bitwise 2023-06-12 17:08:19 +07:00
Mamy André-Ratsimbazafy 36cc2b2e02
Implement comparison 2023-06-12 17:08:19 +07:00
Mamy André-Ratsimbazafy de87739635
Implement types and uint128 primitives 2023-06-12 17:08:19 +07:00
tersec 95b91474ce
remove Nim 1.2 and 1.4 support 2023-06-08 11:08:27 +00:00
tersec 86621eced1
remove pre-Nim 1.2 support (#127) 2023-06-05 11:42:36 +00:00
jangko 493f31de63
reduce compiler warnings 2023-02-23 12:09:45 +07:00
tersec 3472a16fbc
avoid deprecation warnings on Nim 1.6 when using (#121) 2023-02-07 13:41:40 +01:00
G f36623998f
fix(skipPrefixes): fix erroneous strip of 0b in hex numbers (#120)
* fix(skipPrefixes): fix erroneous strip of 0b in hex numbers

* refactor(skipPrefixes): normalize radix checks

* feat(stint): add tests for bin, oct, hex string conversions

* fix(stint): fix cast

* fix(stint): fix typo

* fix(stint): alternative format

* feat(stint): add test

* fix(stint): fix stint width in test
2022-10-03 12:15:45 +02:00
Jacek Sieka c05f75a8da
comment style fix 2022-04-07 09:53:11 +02:00
Kim De Mey e656ad40d1
Enable --styleCheck:usages (#118) 2022-02-24 20:09:53 +01:00
Mamy Ratsimbazafy 49d11d61b8
RangeError are actually defect and not catchable. (#111)
* RangeError are actually defect and not catchable.

* Don't use range types at runtime they throw RangeDefect
2021-10-08 10:08:56 +02:00
Mamy Ratsimbazafy 06e5c4829c
Parsing should raise CatchableError for user inputs (#110) 2021-10-06 18:53:52 +02:00
Timothee Cour 484031fdff fix stint for https://github.com/nim-lang/Nim/pull/18050 2021-07-01 13:16:07 +03:00
zah 9e49b00148 Define a hash function in order to support Stint keys in hash tables (#102)
* Hash stint values as byte blobs; Add a basic test for using stint keys in a table
2019-12-18 14:02:16 +01:00
andri lim f0da0406f0 tidying up range check in constructor 2019-12-13 16:19:41 +02:00
andri lim d98b77c88d fixes #94, implement conversion constructor 2019-12-13 16:19:41 +02:00
andri lim 25c2604b4b cosmetics changes 2019-10-25 19:54:41 +03:00
andri lim 9ec615f0ef disable powmod at compile time 2019-10-25 19:54:41 +03:00
andri lim 2b5d083dac fixes 32bit problem 2019-10-25 19:54:41 +03:00
andri lim 7fe4db62dc add compiletime test for signed int dumphex 2019-10-25 19:54:41 +03:00
andri lim 59acce63b7 fixes intops.shr for Nim 0.19.6 2019-10-23 21:55:47 +09:00
andri lim 0ee6dc5c6a convert runtime signed int mul to vm friendly 2019-10-23 21:55:47 +09:00
andri lim 962932dd6a fixes isNegative only for signed integer 2019-10-23 21:55:47 +09:00
andri lim 7dc26bb714 signed integer 'fromHex' 2019-10-23 21:55:47 +09:00
andri lim 79dfae7d32 fixes typo 2019-10-23 21:55:47 +09:00
andri lim 0cd6b2a052 improve io test coverage + compile time test 2019-10-23 21:55:47 +09:00
andri lim d67cee6f8d tidying up compiletime helpers 2019-10-23 21:55:47 +09:00
andri lim f5116945e6 move compile time convertImpl to compiletile helpers 2019-10-23 21:55:47 +09:00
andri lim affbe30b41 implement compile time helpers 2019-10-23 21:55:47 +09:00
andri lim 0b06077c55 compile time toBytes 2019-10-23 21:55:47 +09:00
andri lim 21dc4c6519 compile time truncate and dumpHex 2019-10-23 21:55:47 +09:00
andri lim 6eb7b7054e
fixes related to Nim v1.0.2 32 bit type inference rule modification 2019-10-19 16:56:18 +07:00
andri lim e084bb7d9d
using tuple comparison when checking for nim version instead of template 2019-08-07 21:28:33 +07:00
andri lim 173699583b
fix #81 remove ashr from API and fix shr on Nim 0.20 2019-08-06 20:25:48 +07:00
Jacek Sieka d154bcf90a
reexport isEven and friends 2019-07-22 10:17:58 +02:00
Jacek Sieka c5247e9d88
stew updates (#82)
* simplify int api (fixes #68)
* implement endians api
* implement some more bitops
2019-07-22 09:53:58 +02:00
Jacek Sieka 33562884a1
std_shims -> stew 2019-07-07 11:50:53 +02:00
andri lim ccf87daac1 implement arithmetic right shift (#76)
* implement arithmetic right shift

* workaround Nim VM 'cast' limitation

* fix high(stint) bug

* fix compile time bit shift bug

* add test for compile time shift and high(stint)

* add tests against ttmath
2019-05-11 15:44:41 +02:00
Jacek Sieka 9c51f9e7d5 use bitops2 from shims (#77) 2019-05-09 21:46:40 +02:00
Ștefan Talpalaru 6853ebe97c
assert() -> doAssert() 2019-03-14 03:43:51 +01:00
Ștefan Talpalaru d002fbb155 fix breakage with Nim HEAD (#73) 2019-01-08 12:39:04 +01:00
Jacek Sieka 360d01d170 Better bitsof implementation (#74)
See https://github.com/nim-lang/Nim/issues/9494
2019-01-07 20:11:45 +01:00
mratsim 308ed51d59 Add 8192-bit overloads 2018-12-04 15:42:00 +01:00
mratsim fa37d957e9 Add one more bitsof overload to support Uint4096 2018-12-04 14:33:19 +01:00
Jacek Sieka edb1ade373
add a few more overloads for calculating bitset size (for eth-bloom) 2018-11-07 09:18:25 -06:00
Jacek Sieka 9027fbea3e
refactoring away for loop macros
* remove experimental for loop macro usage
* make implementation of several operations follow data structure
(recursive data -> recursive implementation)
* rename getSize -> bitsof to avoid bits vs bytes confusion
* fix potential 32-bit issue where asSignedWords cast to `int` even when
`uint64` was used as storage
* `hi` for signed ints now is signed - this replaces `asSignedWords` and
makes several int operations more natural
* fix bit size assert
2018-10-25 12:58:40 +02:00
mratsim 4fe901d33b Use truncate instead of toInt and co 2018-10-08 21:11:06 +00:00
mratsim 2d6ea71657 BREAKING: Change named param from `base` to `radix` in io procs 2018-10-08 21:11:06 +00:00
mratsim 0f5fd20679 NEP-1 (camelCase) 2018-10-08 21:11:06 +00:00
mratsim 65729901db Review: add comment about where Stint is not ideal 2018-10-08 21:11:06 +00:00
mratsim eb6357f4d1 Misse double hash for doc comments 2018-10-08 21:11:06 +00:00
mratsim 53ceaffdfa Fix endianness issue in toInt64 and toUint64 2018-10-08 21:11:06 +00:00
mratsim 5980477e0b Add a description and why choosing a recursive impl for Stint 2018-10-08 21:11:06 +00:00
mratsim f161454309 Add tests for toUint/toUint64, toInt, toInt64 2018-10-08 21:11:06 +00:00
mratsim 7bbe7d8f9f Fix doc of toInt/toUint + add more docs about undefined behaviours 2018-10-08 21:11:06 +00:00
mratsim 7fa6329d4c Change the test flag from mpint_test to stint_test 2018-10-08 21:11:06 +00:00
mratsim 7591373f15 Enable modular arithmetic tests 2018-10-08 21:11:06 +00:00
mratsim 69b5630de1 Use static default argument fix #40 and deprecated significantBytesBE 2018-10-08 21:11:06 +00:00
mratsim 31101a5c5b Add a toUint64 and toInt64 for 32-bit platform (fixes #48) 2018-10-08 21:11:06 +00:00
mratsim 1c29314d8e Add a touint proc fixes #58 2018-10-08 21:11:06 +00:00
mratsim 582466b625 Fix Generic Instantiation too nested in unittest (https://github.com/status-im/nim-stint/pull/66#issuecomment-427557655) + Renable all tests 2018-10-08 21:11:06 +00:00
mratsim f7fcecb395 Export marker + assign to result.data + fix forward decl and visibility issues introduced by the removal of the templates 2018-10-08 21:11:06 +00:00
mratsim ede5b57fa4 Improve uint public API: no template + documentation 2018-10-08 21:11:06 +00:00
Yuriy Glukhov 4e7dc9397c Push experimental 2018-09-06 12:35:12 +03:00
mratsim 7e0289fbdf Fix regression due to when bool restriction 361a2d830a and https://github.com/nim-lang/Nim/issues/7375 2018-08-24 13:34:29 +02:00
Mamy Ratsimbazafy fc27e86061
New {.experimental: "ForLoopMacros".} support (#62)
* Bug https://github.com/nim-lang/Nim/issues/8676 and da41fc1801

* Use a commandline flag
2018-08-20 10:34:28 +02:00
mratsim 215293756a Use the new {.experimental.} pragma. Fix https://github.com/nim-lang/Nim/issues/8676, linked to da41fc1801 2018-08-17 19:34:10 +02:00
coffeepots 2a85ed2e40 Fix multiplication on 32 bit systems (#60) 2018-08-10 08:37:04 +02:00
Luke Parker d6435b37ef Stop single digit strings from throwing an IndexError on `parse` (#59) 2018-08-05 23:47:05 +02:00
Zahary Karadjov 406f1aa317 Added a fromHex helper in the style of the new fromBytes APIs 2018-07-04 18:37:07 +03:00
zah f05feeb865 Relaxed construction from BE bytes (#57)
* Support automatic padding when constructing values from byte arrays

* add a test case for fromBytesBE
2018-07-04 17:34:14 +02:00
zah 6ae8de932d Add explicit generic conversion operators (#56)
The new `to` operators that can be used to constuct Stint types from
regular integer types. These are intented for usage in generic code
such as rlp.nim

Also fixes a bug preventing construction of Stint values from unsigned
integers (because they lack an unary `-` operator).
2018-06-27 12:18:48 +02:00
Mamy Ratsimbazafy 36ec850c4f
Compile time signed ints (#55)
* Refactor asSignedWords, kill 130+ lines

* Allow signed int initialization at compiletime.

* inline procs in uint_mul

* Fix an unfortunate shadowing in high(Int)
2018-06-18 16:44:29 +02:00
Mamy Ratsimbazafy a46c62bc83
Uint - allow compile-time evaluation for all procs (#54)
* Initial commit - allow all ops at compile-time on uint.

* Update benchmark

* Delete commented ideal version of asWordsiterate, it  is obvious from the workaround (and is tracked in the PR)
2018-06-18 12:54:25 +02:00
Mamy Ratsimbazafy 184e22b659
Compile-time creation of Uint (#53)
* Start on allowing compile-time stint. Works for Uint256

* remove and reorder initUintImpl, zero and one procs

* Fix assignation of uint64 to 2xuint32, remove unsafeConv and use const for base/radix

* assign_least_significant_words shouldn't implicitly capture result

* Simplify least significant words macros
2018-06-16 18:54:40 +02:00
Mamy Ratsimbazafy 35c57de63d
lenient_stint, typo stuint vs stint in signed conversion 2018-06-14 18:42:58 +02:00
Mamy Ratsimbazafy 46e0810bd3
Add optional mixed types syntactic sugar (#49)
* Add optional mixed types syntactic sugar

* Rename to lenient_stint - remove literals specialization
2018-06-14 15:53:55 +02:00
Mamy Ratsimbazafy 7707a4b40f
Add overloads for literals only (#50) 2018-05-31 14:31:27 +02:00
Mamy Ratsimbazafy 8e25b30209
fix highest signed int comment 2018-05-17 09:45:42 +02:00
Mamy Ratsimbazafy c588a84f19
wrong variable net only_msb_set to only_msb_unset in high(IntImpl) 2018-05-17 09:43:41 +02:00
Mamy Ratsimbazafy f2d0eab153
Modular arithmetic (#47)
* Add isEven and isOdd functions

* Add modular add, mul, sub pow fixes #18
2018-05-16 10:41:46 +02:00
mratsim 7c11f7da07 add `$` alias for toString 2018-05-15 11:51:59 +02:00
mratsim 1283d582a1 implement a pow for x, y: UintImpl as well 2018-05-14 19:44:39 +02:00
Mamy Ratsimbazafy 11f62d42c9
Add exponentiation - closes #37 (#46)
* Add exponentiation

* Change name to pow (like ttmath) - `^` to discuss
2018-05-14 19:02:39 +02:00
Yuriy Glukhov ad09fe3a94 Corrected package structure 2018-05-08 17:42:42 +03:00