1
0
Fork 0
golang-golang-x-mobile/exp/f32/gen.go
Daniel Baumann 20149b7f3a
Adding upstream version 0.0~git20250520.a1d9079+dfsg.
Signed-off-by: Daniel Baumann <daniel@debian.org>
2025-05-25 10:58:38 +02:00

48 lines
1.1 KiB
Go

// Copyright 2014 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build ignore
package main
/*
This program generates table.go. Invoke it as:
go run gen.go -output table.go
*/
import (
"bytes"
"flag"
"fmt"
"go/format"
"log"
"math"
"os"
)
// N is the number of entries in the sin look-up table. It must be a power of 2.
const N = 4096
var filename = flag.String("output", "table.go", "output file name")
func main() {
b := new(bytes.Buffer)
fmt.Fprintf(b, "// Code generated by go run gen.go; DO NOT EDIT\n\npackage f32\n\n")
fmt.Fprintf(b, "const sinTableLen = %d\n\n", N)
fmt.Fprintf(b, "// sinTable[i] equals sin(i * π / sinTableLen).\n")
fmt.Fprintf(b, "var sinTable = [sinTableLen]float32{\n")
for i := 0; i < N; i++ {
radians := float64(i) * (math.Pi / N)
fmt.Fprintf(b, "%v,\n", float32(math.Sin(radians)))
}
fmt.Fprintf(b, "}\n")
data, err := format.Source(b.Bytes())
if err != nil {
log.Fatal(err)
}
if err := os.WriteFile(*filename, data, 0644); err != nil {
log.Fatal(err)
}
}