Skip to content

Commit 2dd23d6

Browse files
committed
Add test
1 parent 2e6ae02 commit 2dd23d6

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

math/number/parse.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11
package number
22

3-
import (
4-
"math"
5-
"strconv"
6-
)
7-
8-
// Ldexp returns a * 2**b.
9-
func Ldexp(a, b int) float64 {
10-
return math.Ldexp(float64(a), b)
11-
}
3+
import "strconv"
124

135
// MustParseInt returns int from binary string.
146
// It panics if error occurs.

math/number/pow.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
package number
22

3+
import "math"
4+
5+
// Ldexp returns a * 2**b.
6+
func Ldexp(a, b int) float64 {
7+
return math.Ldexp(float64(a), b)
8+
}
9+
310
// Pow returns a**r, the base-a exponential of r.
411
func Pow(a, r int) int {
512
if a == 0 {

math/number/pow_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@ import (
77
"github.com/itsubaki/q/math/number"
88
)
99

10+
func ExampleLdexp() {
11+
fmt.Println(number.Ldexp(1, -2))
12+
fmt.Println(number.Ldexp(3, -2))
13+
fmt.Println(number.Ldexp(3, 4))
14+
15+
// Output:
16+
// 0.25
17+
// 0.75
18+
// 48
19+
}
20+
1021
func ExampleBaseExp() {
1122
a, b, ok := number.BaseExp(125)
1223
fmt.Printf("%v^%v %v", a, b, ok)

0 commit comments

Comments
 (0)