本文整理汇总了Golang中golang.org/x/tools/go/exact.Float64Val函数的典型用法代码示例。如果您正苦于以下问题:Golang Float64Val函数的具体用法?Golang Float64Val怎么用?Golang Float64Val使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Float64Val函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: roundFloat64
func roundFloat64(x exact.Value) exact.Value {
f, _ := exact.Float64Val(x)
if !math.IsInf(f, 0) {
return exact.MakeFloat64(f)
}
return nil
}
开发者ID:herberteuler,项目名称:kythe,代码行数:7,代码来源:expr.go
示例2: constValString
// constValString emulates Go 1.6's go/constant.ExactString well enough
// to make the tests pass. This is just a stopgap until we throw away
// all the *14.go files.
func constValString(v exact.Value) string {
if v.Kind() == exact.Float {
f, _ := exact.Float64Val(v)
return fmt.Sprintf("%g", f)
}
return v.String()
}
开发者ID:idvoretskyi,项目名称:coreos-kubernetes,代码行数:10,代码来源:describe14.go
示例3: FloatVal
// FloatVal is a utility function returns a string constant value from an exact.Value.
func (comp *Compilation) FloatVal(eVal exact.Value, bits int, posStr string) string {
fVal, isExact := exact.Float64Val(eVal)
if !isExact {
comp.LogWarning(posStr, "inexact", fmt.Errorf("constant value %g cannot be accurately represented in float64", fVal))
}
ret := strconv.FormatFloat(fVal, byte('g'), -1, bits)
if fVal < 0.0 {
return fmt.Sprintf("(%s)", ret)
}
return ret
}
开发者ID:henrylee2cn,项目名称:tardisgo,代码行数:12,代码来源:constants.go
示例4: Uint64
// Uint64 returns the numeric value of this constant truncated to fit
// an unsigned 64-bit integer.
//
func (c *Const) Uint64() uint64 {
switch x := c.Value; x.Kind() {
case exact.Int:
if u, ok := exact.Uint64Val(x); ok {
return u
}
return 0
case exact.Float:
f, _ := exact.Float64Val(x)
return uint64(f)
}
panic(fmt.Sprintf("unexpected constant value: %T", c.Value))
}
开发者ID:dylanpoe,项目名称:golang.org,代码行数:16,代码来源:const14.go
示例5: translateExpr
func (c *funcContext) translateExpr(expr ast.Expr) *expression {
exprType := c.p.TypeOf(expr)
if value := c.p.Types[expr].Value; value != nil {
basic := exprType.Underlying().(*types.Basic)
switch {
case isBoolean(basic):
return c.formatExpr("%s", strconv.FormatBool(exact.BoolVal(value)))
case isInteger(basic):
if is64Bit(basic) {
if basic.Kind() == types.Int64 {
d, ok := exact.Int64Val(value)
if !ok {
panic("could not get exact uint")
}
return c.formatExpr("new %s(%s, %s)", c.typeName(exprType), strconv.FormatInt(d>>32, 10), strconv.FormatUint(uint64(d)&(1<<32-1), 10))
}
d, ok := exact.Uint64Val(value)
if !ok {
panic("could not get exact uint")
}
return c.formatExpr("new %s(%s, %s)", c.typeName(exprType), strconv.FormatUint(d>>32, 10), strconv.FormatUint(d&(1<<32-1), 10))
}
d, ok := exact.Int64Val(value)
if !ok {
panic("could not get exact int")
}
return c.formatExpr("%s", strconv.FormatInt(d, 10))
case isFloat(basic):
f, _ := exact.Float64Val(value)
return c.formatExpr("%s", strconv.FormatFloat(f, 'g', -1, 64))
case isComplex(basic):
r, _ := exact.Float64Val(exact.Real(value))
i, _ := exact.Float64Val(exact.Imag(value))
if basic.Kind() == types.UntypedComplex {
exprType = types.Typ[types.Complex128]
}
return c.formatExpr("new %s(%s, %s)", c.typeName(exprType), strconv.FormatFloat(r, 'g', -1, 64), strconv.FormatFloat(i, 'g', -1, 64))
case isString(basic):
return c.formatExpr("%s", encodeString(exact.StringVal(value)))
default:
panic("Unhandled constant type: " + basic.String())
}
}
var obj types.Object
switch e := expr.(type) {
case *ast.SelectorExpr:
obj = c.p.Uses[e.Sel]
case *ast.Ident:
obj = c.p.Defs[e]
if obj == nil {
obj = c.p.Uses[e]
}
}
if obj != nil && typesutil.IsJsPackage(obj.Pkg()) {
switch obj.Name() {
case "Global":
return c.formatExpr("$global")
case "Module":
return c.formatExpr("$module")
case "Undefined":
return c.formatExpr("undefined")
}
}
switch e := expr.(type) {
case *ast.CompositeLit:
if ptrType, isPointer := exprType.(*types.Pointer); isPointer {
exprType = ptrType.Elem()
}
collectIndexedElements := func(elementType types.Type) []string {
var elements []string
i := 0
zero := c.translateExpr(c.zeroValue(elementType)).String()
for _, element := range e.Elts {
if kve, isKve := element.(*ast.KeyValueExpr); isKve {
key, ok := exact.Int64Val(c.p.Types[kve.Key].Value)
if !ok {
panic("could not get exact int")
}
i = int(key)
element = kve.Value
}
for len(elements) <= i {
elements = append(elements, zero)
}
elements[i] = c.translateImplicitConversionWithCloning(element, elementType).String()
i++
}
return elements
}
switch t := exprType.Underlying().(type) {
case *types.Array:
elements := collectIndexedElements(t.Elem())
if len(elements) == 0 {
return c.formatExpr("%s.zero()", c.typeName(t))
}
//.........这里部分代码省略.........
开发者ID:drawapp8,项目名称:gopherjs,代码行数:101,代码来源:expressions.go
示例6: formatExprInternal
//.........这里部分代码省略.........
if val := c.p.Types[e.(ast.Expr)].Value; val != nil {
continue
}
if !hasAssignments {
hasAssignments = true
out.WriteByte('(')
parens = false
}
v := c.newVariable("x")
out.WriteString(v + " = " + c.translateExpr(e.(ast.Expr)).String() + ", ")
vars[i] = v
}
processFormat(func(b, k uint8, n int) {
writeExpr := func(suffix string) {
if vars[n] != "" {
out.WriteString(vars[n] + suffix)
return
}
out.WriteString(c.translateExpr(a[n].(ast.Expr)).StringWithParens() + suffix)
}
switch k {
case 0:
out.WriteByte(b)
case 's':
if e, ok := a[n].(*expression); ok {
out.WriteString(e.StringWithParens())
return
}
out.WriteString(a[n].(string))
case 'd':
out.WriteString(strconv.Itoa(a[n].(int)))
case 't':
out.WriteString(a[n].(token.Token).String())
case 'e':
e := a[n].(ast.Expr)
if val := c.p.Types[e].Value; val != nil {
out.WriteString(c.translateExpr(e).String())
return
}
writeExpr("")
case 'f':
e := a[n].(ast.Expr)
if val := c.p.Types[e].Value; val != nil {
d, _ := exact.Int64Val(val)
out.WriteString(strconv.FormatInt(d, 10))
return
}
if is64Bit(c.p.TypeOf(e).Underlying().(*types.Basic)) {
out.WriteString("$flatten64(")
writeExpr("")
out.WriteString(")")
return
}
writeExpr("")
case 'h':
e := a[n].(ast.Expr)
if val := c.p.Types[e].Value; val != nil {
d, _ := exact.Uint64Val(val)
if c.p.TypeOf(e).Underlying().(*types.Basic).Kind() == types.Int64 {
out.WriteString(strconv.FormatInt(int64(d)>>32, 10))
return
}
out.WriteString(strconv.FormatUint(d>>32, 10))
return
}
writeExpr(".$high")
case 'l':
if val := c.p.Types[a[n].(ast.Expr)].Value; val != nil {
d, _ := exact.Uint64Val(val)
out.WriteString(strconv.FormatUint(d&(1<<32-1), 10))
return
}
writeExpr(".$low")
case 'r':
if val := c.p.Types[a[n].(ast.Expr)].Value; val != nil {
r, _ := exact.Float64Val(exact.Real(val))
out.WriteString(strconv.FormatFloat(r, 'g', -1, 64))
return
}
writeExpr(".$real")
case 'i':
if val := c.p.Types[a[n].(ast.Expr)].Value; val != nil {
i, _ := exact.Float64Val(exact.Imag(val))
out.WriteString(strconv.FormatFloat(i, 'g', -1, 64))
return
}
writeExpr(".$imag")
case '%':
out.WriteRune('%')
default:
panic(fmt.Sprintf("formatExpr: %%%c%d", k, n))
}
})
if hasAssignments {
out.WriteByte(')')
}
return &expression{str: out.String(), parens: parens}
}
开发者ID:drawapp8,项目名称:gopherjs,代码行数:101,代码来源:expressions.go
示例7: fitsFloat64
func fitsFloat64(x exact.Value) bool {
f, _ := exact.Float64Val(x)
return !math.IsInf(f, 0)
}
开发者ID:herberteuler,项目名称:kythe,代码行数:4,代码来源:expr.go
示例8: Complex128
// Complex128 returns the complex value of this constant truncated to
// fit a complex128.
//
func (c *Const) Complex128() complex128 {
re, _ := exact.Float64Val(exact.Real(c.Value))
im, _ := exact.Float64Val(exact.Imag(c.Value))
return complex(re, im)
}
开发者ID:dylanpoe,项目名称:golang.org,代码行数:8,代码来源:const14.go
示例9: Float64
// Float64 returns the numeric value of this constant truncated to fit
// a float64.
//
func (c *Const) Float64() float64 {
f, _ := exact.Float64Val(c.Value)
return f
}
开发者ID:dylanpoe,项目名称:golang.org,代码行数:7,代码来源:const14.go
示例10: newValueFromConst
// newValueFromConst converts a constant value to an LLVM value.
func (fr *frame) newValueFromConst(v exact.Value, typ types.Type) *govalue {
switch {
case v == nil:
llvmtyp := fr.types.ToLLVM(typ)
return newValue(llvm.ConstNull(llvmtyp), typ)
case isString(typ):
if isUntyped(typ) {
typ = types.Typ[types.String]
}
llvmtyp := fr.types.ToLLVM(typ)
strval := exact.StringVal(v)
strlen := len(strval)
i8ptr := llvm.PointerType(llvm.Int8Type(), 0)
var ptr llvm.Value
if strlen > 0 {
init := llvm.ConstString(strval, false)
ptr = llvm.AddGlobal(fr.module.Module, init.Type(), "")
ptr.SetInitializer(init)
ptr.SetLinkage(llvm.InternalLinkage)
ptr = llvm.ConstBitCast(ptr, i8ptr)
} else {
ptr = llvm.ConstNull(i8ptr)
}
len_ := llvm.ConstInt(fr.types.inttype, uint64(strlen), false)
llvmvalue := llvm.Undef(llvmtyp)
llvmvalue = llvm.ConstInsertValue(llvmvalue, ptr, []uint32{0})
llvmvalue = llvm.ConstInsertValue(llvmvalue, len_, []uint32{1})
return newValue(llvmvalue, typ)
case isInteger(typ):
if isUntyped(typ) {
typ = types.Typ[types.Int]
}
llvmtyp := fr.types.ToLLVM(typ)
var llvmvalue llvm.Value
if isUnsigned(typ) {
v, _ := exact.Uint64Val(v)
llvmvalue = llvm.ConstInt(llvmtyp, v, false)
} else {
v, _ := exact.Int64Val(v)
llvmvalue = llvm.ConstInt(llvmtyp, uint64(v), true)
}
return newValue(llvmvalue, typ)
case isBoolean(typ):
if isUntyped(typ) {
typ = types.Typ[types.Bool]
}
return newValue(boolLLVMValue(exact.BoolVal(v)), typ)
case isFloat(typ):
if isUntyped(typ) {
typ = types.Typ[types.Float64]
}
llvmtyp := fr.types.ToLLVM(typ)
floatval, _ := exact.Float64Val(v)
llvmvalue := llvm.ConstFloat(llvmtyp, floatval)
return newValue(llvmvalue, typ)
case typ == types.Typ[types.UnsafePointer]:
llvmtyp := fr.types.ToLLVM(typ)
v, _ := exact.Uint64Val(v)
llvmvalue := llvm.ConstInt(fr.types.inttype, v, false)
llvmvalue = llvm.ConstIntToPtr(llvmvalue, llvmtyp)
return newValue(llvmvalue, typ)
case isComplex(typ):
if isUntyped(typ) {
typ = types.Typ[types.Complex128]
}
llvmtyp := fr.types.ToLLVM(typ)
floattyp := llvmtyp.StructElementTypes()[0]
llvmvalue := llvm.ConstNull(llvmtyp)
realv := exact.Real(v)
imagv := exact.Imag(v)
realfloatval, _ := exact.Float64Val(realv)
imagfloatval, _ := exact.Float64Val(imagv)
llvmre := llvm.ConstFloat(floattyp, realfloatval)
llvmim := llvm.ConstFloat(floattyp, imagfloatval)
llvmvalue = llvm.ConstInsertValue(llvmvalue, llvmre, []uint32{0})
llvmvalue = llvm.ConstInsertValue(llvmvalue, llvmim, []uint32{1})
return newValue(llvmvalue, typ)
}
// Special case for string -> [](byte|rune)
if u, ok := typ.Underlying().(*types.Slice); ok && isInteger(u.Elem()) {
if v.Kind() == exact.String {
strval := fr.newValueFromConst(v, types.Typ[types.String])
return fr.convert(strval, typ)
}
}
panic(fmt.Sprintf("unhandled: t=%s(%T), v=%v(%T)", typ, typ, v, v))
}
开发者ID:hinike,项目名称:llgo,代码行数:96,代码来源:value.go
注:本文中的golang.org/x/tools/go/exact.Float64Val函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论