Debian Codegraph @

exp/f32/f32.go

raw symbols SCIP
1 // Copyright 2014 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 //go:generate go run gen.go -output table.go
6
7 // Package f32 implements some linear algebra and GL helpers for float32s.
8 //
9 // Types defined in this package have methods implementing common
10 // mathematical operations. The common form for these functions is
11 //
12 // func (dst *T) Op(lhs, rhs *T)
13 //
14 // which reads in traditional mathematical notation as
15 //
16 // dst = lhs op rhs.
17 //
18 // It is safe to use the destination address as the left-hand side,
19 // that is, dst *= rhs is dst.Mul(dst, rhs).
20 //
21 // # WARNING
22 //
23 // The interface to this package is not stable. It will change considerably.
24 // Only use functions that provide package documentation. Semantics are
25 // non-obvious. Be prepared for the package name to change.
26 package f32scip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/
27
28 import (
29 "encoding/binaryscip-go gomod github.com/golang/go/src go1.24.0 `encoding/binary`/"
30 "fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/"
31 "mathscip-go gomod github.com/golang/go/src go1.24.0 math/"
32 )
33
34 type Radianscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/Radian# float32
35
36 func Cosscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/Cos().(x float32) float32 {
37 const n = sinTableLenscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/sinTableLen.
38 i := uint32(int32(x * (n / mathscip-go gomod github.com/golang/go/src go1.24.0 math/.Piscip-go gomod github.com/golang/go/src go1.24.0 math/Pi.)))
39 i += n / 2
40 i &= 2*n - 1
41 if i >= n {
42 return -sinTablescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/sinTable.[i&(n-1)]
43 }
44 return sinTablescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/sinTable.[i&(n-1)]
45 }
46
47 func Sinscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/Sin().(x float32) float32 {
48 const n = sinTableLenscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/sinTableLen.
49 i := uint32(int32(x * (n / mathscip-go gomod github.com/golang/go/src go1.24.0 math/.Piscip-go gomod github.com/golang/go/src go1.24.0 math/Pi.)))
50 i &= 2*n - 1
51 if i >= n {
52 return -sinTablescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/sinTable.[i&(n-1)]
53 }
54 return sinTablescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/sinTable.[i&(n-1)]
55 }
56
57 func Sqrtscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/Sqrt().(x float32) float32 {
58 return float32(mathscip-go gomod github.com/golang/go/src go1.24.0 math/.Sqrtscip-go gomod github.com/golang/go/src go1.24.0 math/Sqrt().(float64(x))) // TODO(crawshaw): implement
59 }
60
61 func Tanscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/Tan().(x float32) float32 {
62 return float32(mathscip-go gomod github.com/golang/go/src go1.24.0 math/.Tanscip-go gomod github.com/golang/go/src go1.24.0 math/Tan().(float64(x))) // TODO(crawshaw): fast version
63 }
64
65 // Bytes returns the byte representation of float32 values in the given byte
66 // order. byteOrder must be either binary.BigEndian or binary.LittleEndian.
67 func Bytesscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/Bytes().(byteOrder binaryscip-go gomod github.com/golang/go/src go1.24.0 `encoding/binary`/.ByteOrderscip-go gomod github.com/golang/go/src go1.24.0 `encoding/binary`/ByteOrder#, values ...float32) []byte {
68 le := false
69 switch byteOrder {
70 case binaryscip-go gomod github.com/golang/go/src go1.24.0 `encoding/binary`/.BigEndianscip-go gomod github.com/golang/go/src go1.24.0 `encoding/binary`/BigEndian.:
71 case binaryscip-go gomod github.com/golang/go/src go1.24.0 `encoding/binary`/.LittleEndianscip-go gomod github.com/golang/go/src go1.24.0 `encoding/binary`/LittleEndian.:
72 le = true
73 default:
74 panic(fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Sprintf().("invalid byte order %v", byteOrder))
75 }
76
77 b := make([]byte, 4*len(values))
78 for i, v := range values {
79 u := mathscip-go gomod github.com/golang/go/src go1.24.0 math/.Float32bitsscip-go gomod github.com/golang/go/src go1.24.0 math/Float32bits().(v)
80 if le {
81 b[4*i+0] = byte(u >> 0)
82 b[4*i+1] = byte(u >> 8)
83 b[4*i+2] = byte(u >> 16)
84 b[4*i+3] = byte(u >> 24)
85 } else {
86 b[4*i+0] = byte(u >> 24)
87 b[4*i+1] = byte(u >> 16)
88 b[4*i+2] = byte(u >> 8)
89 b[4*i+3] = byte(u >> 0)
90 }
91 }
92 return b
93 }