Skip to content

Commit

Permalink
added Constants.huff and updated Helper.huff
Browse files Browse the repository at this point in the history
  • Loading branch information
Prabhat1308 committed Oct 1, 2023
1 parent 0c2cbc3 commit bcc16cc
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/Complex.huff
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include './Helper.huff'
#include './Constants.huff'

#define function addZ(int256 , int 256 , int256 , int256) returns (int256 ,int256)
#define function subZ(int256 , int 256 , int256 , int256) returns (int256 ,int256)
Expand Down Expand Up @@ -153,16 +154,16 @@
swap2 // [Re(A),Re(B),Im(A)*Im(B),Re(B)*Im(A)-Re(A)*Im(B),X]
mul // [Re(A)*Re(B),Im(A)*Im(B),Re(B)*Im(A)-Re(A)*Im(B),X]
add // [Re(A)*Re(B)+Im(A)*Im(B),Re(B)*Im(A)-Re(A)*Im(B),X] ; Let Re(A)*Re(B)+Im(A)*Im(B) be Y and Re(B)*Im(A)-Re(A)*Im(B) be W
0xDE0B6B3A7640000 // [1e18,Y,W,X]
[X3]// [1e18,Y,W,X]
mul // [1e18*Y,W,X]
dup3 // [X,1e18*Y,W,X]
swap1 // [1e18*Y,X,W,X]
div // [1e18*Y/X,W,X]
sdiv // [1e18*Y/X,W,X]
swap2 // [X,W,1e18*Y/X]
swap1 // [W,X,1e18*Y/X]
0xDE0B6B3A7640000 // [1e18,W,X,1e18*Y/X]
[X3]// [1e18,W,X,1e18*Y/X]
mul // [1e18*W,X,1e18*Y/X]
div // [1e18*W/X,1e18*Y/X]
sdiv // [1e18*W/X,1e18*Y/X]
swap1 // [1e18*Y/X,1e18*W/X]

}
Expand Down Expand Up @@ -193,12 +194,12 @@
CALC_R() // [r,Re(a),Im(a)]
dup1 // [r,r,Re(a),Im(a)]
0x00 // [0,r,r,Re(a),Im(a)]
lt // [0<r,r,Re(a),Im(a)]
slt // [0<r,r,Re(a),Im(a)]
case1
jumpi
swap2 //[Im(a),Re(a),r] , r is negative
P_ATAN2() //[T,r]
0x9C2007651B2500000 //[180e18,T,r]
[X4] //[180e18,T,r]
add // [180e18+T,r]
swap1 //[r,T+180e18]

Expand All @@ -217,7 +218,7 @@
//INPUT STACK => [T,r]
dup1 // [T,T,r]
0x00 // [0,T,T,r]
lt // [0<T,T,r]
slt // [0<T,T,r]
case1
jumpi

Expand All @@ -226,3 +227,4 @@




4 changes: 4 additions & 0 deletions src/Constants.Huff
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#define constant X1 = 0x2B965CF5968C000 // 1963e14
#define constant X2 = 0xD9FB2F2E0004000 // 9817e14
#define constant X3 = 0xDE0B6B3A7640000 // 1e18
#define constant X4 = 0x9C2007651B2500000 //180e18
35 changes: 35 additions & 0 deletions src/Helper.huff
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include './Constants.huff'

#define macro PUT_C1() = takes(0) returns(1){
0x04 // [2]
0x2B992DDFA2324A14 //[ 3141592653589793300,4]
sdiv // [3141592653589793300/4]
}

#define macro PUT_C2() = takes(0) returns(1){
PUT_C1() //[c1]
0x03 //[3,c1]
mul // [3*c1]
}

#define macro ABS() = takes(1) returns(1){
//Input Stack => [x]
0x00 //[0,x]
dup2 //[x,0,x]
slt // [x<0,x]
reverse
jumpi

reverse:
dup1 //[x,x]
dup1 //[x,x,x]
add //[2x,x]
swap1 //[x,2x]
sub //[-x]
}

#define macro PUT_X3_CUBE = takes(0) returns(1){
0x03 //[2]
[X3] //[1e18,3]
exp //[1e54]
}

0 comments on commit bcc16cc

Please sign in to comment.