Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
870 views
in Technique[技术] by (71.8m points)

floating point - Constant truncated to integer

The following GO program gives the error:

./fft.go:13: constant -6.28319 truncated to integer
./fft.go:13: cannot use -7 * k / N (type int) as type float64 in assignment

Program:

package main

import (
    "math"
    "fmt"
)

func main() {
    fmt.Println("Hello world ",math.E)

    var k, N int = 1, 10
    var ans float64 = 0
    var c float64 = (-2.0 * math.Pi * k) / N
    x := make([]float64,N)
    for i := 0; i < len(x); i++ {
        x[i] = 1
    }
    ans = 0
    for i := 0; i < N; i++ {
        ans += x[i] * math.E
    }
    fmt.Println(ans)
}

Why cant I use an int in a type of float64 ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...