Commit Graph

122 Commits

Author SHA1 Message Date
Zahary Karadjov 20b94bff4b Added a fromHex helper in the style of the new fromBytes APIs 2018-07-04 18:35:16 +03:00
Zahary Karadjov 0cd82dd654 add a test case for fromBytesBE 2018-07-04 17:44:55 +03:00
Zahary Karadjov f00f525352 Support automatic padding when constructing values from byte arrays 2018-07-04 17:23:13 +03: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
mratsim fac7c8db3c Comment out test-only dependencies quicktest and ttmath.
(Repeated annoying "Dependency for ttmath: do you want to replace byteutils" while compiling nimbus)
2018-06-10 13:11:24 +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 4e0724790c
Merge pull request #44 from status-im/pkg-struct
Corrected package structure
2018-05-08 20:57:37 +03:00
Yuriy Glukhov ad09fe3a94 Corrected package structure 2018-05-08 17:42:42 +03:00
mratsim 0ad3239907 Fix #45 - shl/shr "halfSize" should have the same type as the input 2018-05-08 16:38:11 +02:00
mratsim 37c969b11e Merge branch 'master' of https://github.com/status-im/nim-stint 2018-05-08 15:47:36 +02:00
mratsim 0209af26a2 Add restrict pragma for readUintBE and toByteArrayBE 2018-05-08 15:47:32 +02:00
Mamy Ratsimbazafy 78b2d5af29
32-bits - use guaranted 64-bit types in VM for mul fix #42 (#43) 2018-05-08 15:31:30 +02:00
mratsim 8cd48fc0e9 Add Appveyor badge + use the blue MIT badge 2018-05-08 15:30:58 +02:00
mratsim 012dcf288c Add toHex shortcut for toString(16) 2018-05-08 14:44:07 +02:00
mratsim c296e14dde Merge branch 'master' of https://github.com/status-im/nim-stint 2018-05-08 13:50:05 +02:00
mratsim 2efaf3e623 Export zero and one proc 2018-05-08 13:49:58 +02:00
Mamy Ratsimbazafy adb75b32b8
[IO]: Add readUintBE, hexToUint, toByteArrayBE
* Add readUintBE and toByteArrayBE proc

* Add readUintBE, hexToUint, to ByteArrayBE and reorder parse arguments + tests
2018-05-08 13:21:04 +02:00
Mamy Ratsimbazafy 1653a8815f
Restrict pragma: use C, C++, VCC + GCC + LLVM compatible syntax (#41) 2018-05-08 11:46:21 +02:00
mratsim 1b7423eacd Export countLeadingZeroBits 2018-05-06 23:02:50 +02:00
mratsim 7dad3f89d8 Export string parsing shortcut "u256" 2018-05-06 22:41:49 +02:00
mratsim 1ff544eabf Remove the fooPragma placeholder (for noinit) 2018-05-06 22:29:08 +02:00
mratsim 0dae6897b1 high/low was missing the internal proc 2018-05-06 22:24:51 +02:00
mratsim 8c0d830acf Export high and low proc 2018-05-06 22:19:00 +02:00
mratsim b5e3e316cb use a more reasonable 10000 tests by default 2018-05-04 10:02:46 +02:00
mratsim 0a1129b36a Update comment displayed in property-based testing 2018-05-04 00:20:32 +02:00
mratsim 40f33238d9 Update uint256 to display the number of iterations 2018-05-04 00:14:51 +02:00
Mamy Ratsimbazafy 4c055e42a7
Add uint256 fuzz test vs TTMath (#34) + Fix multiplication carry bug #36
* Add uint256 fuzz test vs TTMath

* fix the compilation of property_based_uint256

* Fix multiplication carry bug #35

* Change comment in test
2018-05-04 00:11:07 +02:00
Zahary Karadjov c6b55f168f fix the compilation of property_based_uint256 2018-05-03 21:10:55 +03:00
mratsim 4a827027b7 Fix Travis script 2018-05-03 11:35:07 +02:00
mratsim b731108b1c Update Quicktest & Continuous Integration configuration to latest. 2018-05-03 11:07:33 +02:00
mratsim 18e73e7168 Merge branch 'master' of https://github.com/status-im/nim-stint 2018-05-02 18:02:17 +02:00
mratsim c9cba06db1 Make ttmath testing compile 2018-05-02 18:02:13 +02:00
Mamy Ratsimbazafy 0ee1fb3ec8
Fix #30 - modulo failures (#32)
* Add corner cases to test suite

* Add failing div2n1n case

* Fix test and fix #30

* Add to tests

* Fix failing tests due to Nim string change between Apr 27 and Apr 29 (doc: 5237ef4f52)
2018-05-02 17:49:31 +02:00
mratsim d68c0bf44a Fix failing tests due to Nim string change between Apr 27 and Apr 29 (doc: 5237ef4f52) 2018-05-02 17:24:17 +02:00
Mamy Ratsimbazafy fd0482180f
Add bigint serialization (hex and decimal) (#29)
* Add serialization for decimal and hex

* Fix carry bug in signed add

* Add parsing test

* Improve highlow for int, remove most_significant_word_mut

* make conversion toString compile

* Add division corner case test

* Remove a buggy division shortcut

* Fix decimal string conversion

* Fix hex dumping

* Fix power of 2 division (what was I thinking?)

* Add hexdump test

* Move runtime check to compile-time

* Fix static assert check

* more compile-time asserts

* Fix parsing of negative hex numbers, add test_io to the suite

* dump default to bigEndian, split toString in Stint and Stuint

* Add (failing) tests with big ints conversion

* Temporarily remove all the noInit pragma
2018-04-30 13:38:55 +02:00
Mamy Ratsimbazafy f520f7817b
Merge pull request #27 from status-im/signed-integers
Add Signed integers
2018-04-26 13:06:51 +02:00
mratsim 5ac6e229a0 update signed multiplication comment 2018-04-26 12:34:28 +02:00
mratsim 6d2562ff5f Implement absolute value and signed modulo/division 2018-04-26 12:27:02 +02:00
mratsim 8727adfcf6 Implement signed multi-precision multiplication + tests 2018-04-25 22:48:25 +02:00