Skip to content

Commit

Permalink
math_mod for stdlib #54
Browse files Browse the repository at this point in the history
  • Loading branch information
dbaumgarten committed Jul 1, 2021
1 parent b21dbb2 commit 4eb35c0
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 4 deletions.
8 changes: 4 additions & 4 deletions stdlib/bindata.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions stdlib/src/math_advanced.nolol
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,8 @@ end
macro math_abs(x) expr
abs(x)
end

// Returns x%m (even on basic chips)
macro math_mod(x,m) expr
x%m
end
5 changes: 5 additions & 0 deletions stdlib/src/math_basic.nolol
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,9 @@ end
// Returns the next lower integer to x
macro math_floor(x) expr
x/1000*1000
end

// Returns x%m (even on basic chips)
macro math_mod(x,m) expr
x-x/m/1000*1000*m
end
3 changes: 3 additions & 0 deletions stdlib/stdlib_advanced_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ cases:
sign3: 1
floor1: 1
floor2: 1
mod1: 1
mod2: 1
mod3: 1
pop1: 1
pop2: 1
cont1: 1
Expand Down
3 changes: 3 additions & 0 deletions stdlib/stdlib_basic_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ cases:
sign3: 1
floor1: 1
floor2: 1
mod1: 1
mod2: 1
mod3: 1
pop1: 1
pop2: 1
cont1: 1
Expand Down
3 changes: 3 additions & 0 deletions stdlib/stdlib_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ cases:
sign3: 1
floor1: 1
floor2: 1
mod1: 1
mod2: 1
mod3: 1
pop1: 1
pop2: 1
cont1: 1
Expand Down
4 changes: 4 additions & 0 deletions stdlib/testcases.nolol
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ include "std/logic"
:floor1=math_floor(5.5)==5
:floor2=math_floor(5)==5

:mod1=math_mod(11,10)==1
:mod2=math_mod(5,-3)==2
:mod3=math_mod(-5,3)==-2

string="abc"
string_pop(string,popout); :pop1=popout=="c"
:pop2=string=="ab"
Expand Down

0 comments on commit 4eb35c0

Please sign in to comment.