Skip to content

Commit b3f09d8

Browse files
authored
Merge pull request #3 from EngoEngine/sin-and-sqrt-for-js
added compatibility with wasm / gopherjs
2 parents afa637d + f726760 commit b3f09d8

File tree

11 files changed

+49
-9
lines changed

11 files changed

+49
-9
lines changed

sin.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
// Use of this source code is governed by a BSD-style
66
// license that can be found in the LICENSE file.
77

8+
// +build !js
9+
810
package math
911

1012
/*

sin_386.s

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
// Use of this source code is governed by a BSD-style
66
// license that can be found in the LICENSE file.
77

8+
// +build !js
9+
810
#include "textflag.h"
911

1012
// func Cos(x float32) float32
@@ -48,4 +50,3 @@ TEXT ·Sin(SB),NOSPLIT,$0
4850
FSIN // F0=sin(reduced_x)
4951
FMOVFP F0, ret+4(FP)
5052
RET
51-

sin_amd64.s

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
// Use of this source code is governed by a BSD-style
66
// license that can be found in the LICENSE file.
77

8+
// +build !js
9+
810
#include "textflag.h"
911

1012
TEXT ·Sin(SB),NOSPLIT,$0

sin_js.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// +build js
2+
3+
package math
4+
5+
import (
6+
stdmath "math"
7+
)
8+
9+
func Cos(x float32) float32 {
10+
return float32(stdmath.Cos(float64(x)))
11+
}
12+
13+
func Sin(x float32) float32 {
14+
return float32(stdmath.Cos(float64(x)))
15+
}

sqrt.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5+
// +build !js
6+
57
package math
68

79
// The original C code and the long comment below are

sqrt_386.s

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5+
// +build !js
6+
57
#include "textflag.h"
68

7-
// func Sqrt(x float32) float32
9+
// func Sqrt(x float32) float32
810
TEXT ·Sqrt(SB),NOSPLIT,$0
911
SQRTSS x+0(FP), X0
1012
MOVSS X0, ret+4(FP)

sqrt_amd64.s

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5+
// +build !js
6+
57
#include "textflag.h"
68

79
// func Sqrt(x float32) float32

sqrt_js.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// +build js
2+
3+
package math
4+
5+
import (
6+
stdmath "math"
7+
)
8+
9+
func Sqrt(x float32) float32 {
10+
return float32(stdmath.Sqrt(float64(x)))
11+
}

stubs_arm.s

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,18 @@
33
// license that can be found in the LICENSE file.
44

55
// +build arm
6+
// +build !js
67

78
#include "textflag.h"
89

9-
// func Sqrt(x float32) float32
10+
// func Sqrt(x float32) float32
1011
TEXT ·Sqrt(SB),NOSPLIT,$0
1112
JMP ·sqrt(SB)
1213

13-
// func Cos(x float32) float32
14+
// func Cos(x float32) float32
1415
TEXT ·Cos(SB),NOSPLIT,$0
1516
JMP ·cos(SB)
1617

17-
// func Sin(x float32) float32
18+
// func Sin(x float32) float32
1819
TEXT ·Sin(SB),NOSPLIT,$0
1920
JMP ·sin(SB)

stubs_arm64.s

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,18 @@
33
// license that can be found in the LICENSE file.
44

55
// +build arm64
6+
// +build !js
67

78
#include "textflag.h"
89

9-
// func Sqrt(x float32) float32
10+
// func Sqrt(x float32) float32
1011
TEXT ·Sqrt(SB),NOSPLIT,$0
1112
JMP ·sqrt(SB)
1213

13-
// func Cos(x float32) float32
14+
// func Cos(x float32) float32
1415
TEXT ·Cos(SB),NOSPLIT,$0
1516
JMP ·cos(SB)
1617

17-
// func Sin(x float32) float32
18+
// func Sin(x float32) float32
1819
TEXT ·Sin(SB),NOSPLIT,$0
1920
JMP ·sin(SB)

stubs_ppc64x.s

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
// license that can be found in the LICENSE file.
44

55
// +build ppc64 ppc64le
6+
// +build !js
67

78
#include "textflag.h"
89

9-
// func Sqrt(x float32) float32
10+
// func Sqrt(x float32) float32
1011
TEXT ·Sqrt(SB),NOSPLIT,$0
1112
JMP ·sqrt(SB)

0 commit comments

Comments
 (0)