-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7ee2a16
commit a10250f
Showing
13 changed files
with
786 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Prover.toml | ||
Verifier.toml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,7 @@ | |
mlp, | ||
'src/main.nr', | ||
'Prover.toml', | ||
'../zkfloat/lib.nr', | ||
'../zkfloat/zkfloat.nr', | ||
7 | ||
) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
19342440604102b52f14b0f87de5843660fcd75d80bf02b1e3d1a19ec2041ec30e73aad005e70aa5960820ea8d892073e626c9d1f784da9b450568bbd96ed84f094ffdc414c4bff828af65f8f9337ff56c30b525d2230b0ad49694b93ff7edb10421af5f3f654c811b7b50749dc594ed5c34928a7bbd5de159d8c294c5f6f0220074d2610d5800c865fd2dd91ea3b0bb0eb8c9696c773028e46585976ed6970c295455b7dc3d4cbcb66b046aa90f7dc6c131a48487b54b14b8bf1a8fac5dea601b18bee62f9ada54217593631ed8a7c0b0e3212e3bc5562cfab7f8c565468e0d0f05a84d749d41fc144140c31a0bd4824931f51e9843987542057e403ad2ac720b5ebaf074955b88a1f491a3043f46ffc817606f901c80ec1def23a6da97e6bf22af4ded3cc2979fcfbae78df92ff8aba420f29ccd24ffb33b1cd8125c621cb528275129c59191e7c0eeedee52810351c5394c53e0326561d10169be791f5bdb211a905b57e902c57ab3d0be0efbd287451577366f7137050de3fb6bef42ddd9155b3ffea3d919bb1367b559b6214d9ab8e0c9d8619e3750f7ef2cbff90538860af19e54a647c4353260aef5f7ea85843c7396f88495ce3b198b7fe90f64ced822fea70ece6f08e8623058e4e614dcaaf71d9fece6e8e599f4b5eb2f6d51042e0b0b97da63f59b282de5aac4cab8e8de907f288bea19c3907d2dff3c0589233c22c095efd68f36d1fc9270bfbafabbd2999d91610354bfd21358ad84d1a280d519f3cb041c3f9286f3ebab5f4609906943290e84f0224b71dc35cff6483862102b277500bcc11b5802b695818de50bb589de6ceba53d904478ccb41134976b2703d881d47496311c8ada54a5ab54c951045c5b7e3bf5fab798097f647712f62e159a72479f9d67df1787658ccd40bb9ba3ed718aea1ba3aa301b5afc818062c3096a41efa491e1b1e2924f77c27f65f10ec7144aea2e88b02c6c679b29ef917d293ce8d3b257bfdbdd3d80660c3ce6e43cd2da65a35734924bc2922d0e3c152021f7f08e7368354ae802b6c4c02c1f22246dd22beb4e55b7aeb06a7ec940a12e1a1e647e3489aa3884c6a5cf3a65de32e624fc91c2b9733ef6c3fca7fe49229c26c6133fbb593de8a5e763c348e519871ff42b7999fd4c6a37ab9ca329dbb0330946f258e1f71daf9c4cff683c4b11cd782505ca836696c34dde0c8ca425673924a2f57e041b03cb5316518fda6fb56fc63c069b34b65b5ce7aeb82516217c3021338e565236ddb0d88f7b8c970b73b8f63eb43c849c480f1946840589eae96f0d31ced6b34c7dd277da87b573b760c91b0764a4c7bbcacc732eaf379a6a5ff82885d76de6d4f001e943f2fef2f06a17730cfc9b9c78342e2abbb9faeb60d5cc06570fb363564d8c25005c86fc062679811dc7049ef661dfe7e08a07161a978f20c35b807869f8eec45a89ba2021ee6df276d668fca7472b5031196389bad3cd2a94ce243807bf60debcf9dcb2ab8a5ad64fd71ada216b6718c7f321c22ef2db121116f10e8b01ea5282bce4eeff281fba8b74d8430a2e4770817c34b6ebcfea2e28be5adda0dbf91a8002eeba205f9bb012802c2cfbb5d95e63dcd91f41d3cd1396f77605708cd8c95ff3f3fdfc2271c6c347e588f29cab104fda178176d534 |
128 changes: 128 additions & 0 deletions
128
skproof-package/build/lib/skproof/float_num/FloatNum.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
class FloatNum: | ||
""" | ||
Class for representing base10 floating point numbers | ||
in format of base10 mantissa and base10 exponent. | ||
The exponent is shifted by a fixed value to prevent usage of negative values | ||
for negative exponents. | ||
Attributes | ||
---------- | ||
mantissa : int | ||
unsigned integer value representing the significant digits of the number (max "precision" digits) | ||
exponent: int | ||
signed integer value of the exponent | ||
precision: int | ||
unsigned integer value representing the number of the significant digits in mantissa | ||
exp_pad: int | ||
unsigned integer value for shifting the original exponent (default is 0) | ||
Methods | ||
------- | ||
truncate() | ||
Truncating the value of the mantissa to "precission" number of digits, | ||
while updating the exponent | ||
__add__(num_2) -> FloatNum | ||
Overrides + operator, adds the value of the FloatNum to the other and returns the resulting FloatNum | ||
__mul__(num_2) -> FloatNum | ||
Overrides * operator, multiplies the value of the FloatNum to the other and returns the resulting FloatNum | ||
__gt__(num_2) -> boolean | ||
Overrides > operator, returns true if the value of the FloatNum is greater than the other one | ||
__lt__(num_2) -> boolean | ||
Overrides > operator, returns true if the value of the FloatNum is less than the other one | ||
get_noir_input() -> string | ||
Returns the string representation of the FloatNum object using Noir language struct syntax | ||
get_prover_input() -> string | ||
Returns the string representation of the FloatNum object using and array syntax for the Noir language Prover.toml input file | ||
truncated() -> FloatNum | ||
Returns truncated value of the FloatNum | ||
__str__() -> string | ||
Returns string representation of the FloatNum in scientific notation (<mantissa>e<exponent>) | ||
""" | ||
|
||
def __init__(self, mantissa, exponent, precision, exp_pad=0): | ||
self.precision = precision | ||
self.mantissa = mantissa | ||
|
||
# Example: | ||
# Original exponent = -1 | ||
# exp_pad = 100 | ||
# shifted exponent = 99 | ||
self.exponent = exponent + exp_pad | ||
|
||
def truncate(self): | ||
tr = self.truncated(self.mantissa, self.exponent) | ||
self.mantissa = tr.mantissa | ||
self.exponent = tr.exponent | ||
return self | ||
|
||
def __add__(self, num_2): | ||
mant_1 = self.mantissa | ||
mant_2 = num_2.mantissa | ||
|
||
exp_1 = self.exponent | ||
exp_2 = num_2.exponent | ||
exp = exp_1 | ||
diff = abs(exp_1 - exp_2) | ||
if self.exponent < num_2.exponent: | ||
mant_2 *= 10 ** diff | ||
exp = exp_2 - diff | ||
else: | ||
mant_1 *= 10 ** diff | ||
exp = exp_1 - diff | ||
|
||
sum_mant = mant_1 + mant_2 | ||
|
||
return self.truncated(sum_mant, exp) | ||
|
||
def __mul__(self, num_2): | ||
mant_1 = self.mantissa | ||
mant_2 = num_2.mantissa | ||
|
||
exp_1 = self.exponent | ||
exp_2 = num_2.exponent | ||
|
||
return self.truncated(mant_1 * mant_2, (exp_1 + exp_2 - 100)) | ||
|
||
def __gt__(self, num_2): | ||
return self.mantissa * (10 ** (self.exponent - 100)) > num_2.mantissa * (10 ** (num_2.exponent - 100)) | ||
|
||
def __lt__(self, num_2): | ||
return self.mantissa * (10 ** (self.exponent - 100)) < num_2.mantissa * (10 ** (num_2.exponent - 100)) | ||
|
||
def get_noir_input(self): | ||
sign = 0 | ||
mant = self.mantissa | ||
exp = self.exponent | ||
if mant < 0: | ||
sign = 1 | ||
mant = -mant | ||
|
||
return 'Float {' f'sign: {sign}, mantissa: {mant}, exponent: {exp}' + ' }' | ||
|
||
def get_prover_input(self): | ||
sign = 0 | ||
mant = self.mantissa | ||
exp = self.exponent | ||
if mant < 0: | ||
sign = 1 | ||
mant = -mant | ||
|
||
return f'["{sign}", "{mant}", "{exp}"]' | ||
|
||
def truncated(self, mant, exp): | ||
if len(str(abs(mant))) > self.precision: | ||
l = len(str(abs(mant))) | ||
sign_comp = 0 | ||
if mant < 0: | ||
sign_comp = 1 | ||
prec_diff = abs(l - self.precision) | ||
mant = int(str(mant)[:self.precision + sign_comp]) | ||
exp += prec_diff | ||
|
||
if mant == 0: | ||
exp = 100 | ||
|
||
return FloatNum(mant, exp, self.precision) | ||
|
||
def __str__(self): | ||
return f'{self.mantissa}e{self.exponent}' |
Empty file.
Oops, something went wrong.