Skip to content

Commit

Permalink
fixed division by zero error
Browse files Browse the repository at this point in the history
  • Loading branch information
ineiti committed Aug 11, 2017
1 parent 01bcd04 commit 0cd029c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
9 changes: 8 additions & 1 deletion simul/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ func CheckHosts(rc *platform.RunConfig) {
if depth == 0 || hosts == 0 {
log.Fatal("No BF and no Depth or hosts given - stopping")
}
bf = 2
bf = 1
for calcHosts(bf, depth) < hosts {
bf++
}
Expand All @@ -264,6 +264,13 @@ func CheckHosts(rc *platform.RunConfig) {
// 3rd level: bf^3
// So total: sum(level=0..depth)(bf^level)
func calcHosts(bf, depth int) int {
if bf <= 0 {
log.Fatal("illegal branching-factor")
} else if depth <= 0 {
log.Fatal("illegal depth")
} else if bf == 1 {
return depth + 1
}
return int((1 - math.Pow(float64(bf), float64(depth+1))) /
float64(1-bf))
}
Expand Down
1 change: 1 addition & 0 deletions simul/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ func TestBuild(t *testing.T) {

func TestDepth(t *testing.T) {
testStruct := []struct{ BF, depth, hosts int }{
{1, 1, 2},
{2, 1, 3},
{3, 1, 4},
{3, 2, 13},
Expand Down

0 comments on commit 0cd029c

Please sign in to comment.