Ejemplo n.º 1
0
// Int64 returns the numeric value of this literal truncated to fit
// a signed 64-bit integer.
//
func (l *Literal) Int64() int64 {
	switch x := l.Value; x.Kind() {
	case exact.Int:
		if i, ok := exact.Int64Val(x); ok {
			return i
		}
		return 0
	case exact.Float:
		f, _ := exact.Float64Val(x)
		return int64(f)
	}
	panic(fmt.Sprintf("unexpected literal value: %T", l.Value))
}
Ejemplo n.º 2
0
// Complex128 returns the complex value of this literal truncated to
// fit a complex128.
//
func (l *Literal) Complex128() complex128 {
	re, _ := exact.Float64Val(exact.Real(l.Value))
	im, _ := exact.Float64Val(exact.Imag(l.Value))
	return complex(re, im)
}
Ejemplo n.º 3
0
// Float64 returns the numeric value of this literal truncated to fit
// a float64.
//
func (l *Literal) Float64() float64 {
	f, _ := exact.Float64Val(l.Value)
	return f
}