本文整理汇总了Golang中strconv.Atof函数的典型用法代码示例。如果您正苦于以下问题:Golang Atof函数的具体用法?Golang Atof怎么用?Golang Atof使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Atof函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
screen_width := 1280;
screen_height := 720;
benchmark_mode := false; // true -> loop 50 times to benchmark
canvas := canvas.EmptyCanvasImage(screen_width, screen_height, canvas.Color32(0xff000000));
g := new(gyu3d.G3DContext);
g.SetViewport(gyu3d.StandardViewport(screen_width, screen_height));
g.SetProjection(
gyu3d.IdentityM44().SetPerspective(float(screen_width)*0.006, float(screen_height)*0.006, 1.8, 100.0)
);
lx, ly := .1, -0.3;
if len(flag.Args()) == 2 {
lx, _ = strconv.Atof(flag.Args()[0]);
ly, _ = strconv.Atof(flag.Args()[1]);
}
g.ResetTransforms();
g.ViewMatrix.LookAt(0,1,0, -1.2,1.9,7, -0.5,0.9,0);
g.Update();
// draw
drawTestScene(canvas, g, lx, ly, benchmark_mode);
// export image
outfile,e := file.WritableFile("./out.png");
if e == nil {
png.Encode(outfile, canvas);
outfile.Close();
}
fmt.Printf("done\n");
}
示例2: parseBranchLength
func parseBranchLength(pi ParserInput, pos int) (float, int) {
pos = skipWhitespace(pi, pos)
// expect + consume ':'
if pi.CharAt(pos) != ':' {
//throw new RuntimeException("parse error: parseBranchLength expects ':' at " + ptr);
return 0.0, 0
} else {
pos++
pos = skipWhitespace(pi, pos)
flen := findFloat(pi, pos)
if flen == pos {
fmt.Printf("error: missing float number at %d\n", pos)
}
blen, _ := strconv.Atof(pi.Substring(pos, flen))
pos = flen
return blen, pos
}
panic("unreachable")
}
示例3: Analyze
func (this *Lexicon) Analyze() {
tokenizer := strutils.NewStrTokens(this.buffer.String())
outer:
for tokenizer.HasMoreTokens() {
token := tokenizer.NextToken()
//keywords, separators, operators, literals, identifiers
for _, k := range keywords {
if k == token {
this.keywords.Push(token)
continue outer
}
}
for _, s := range separators {
if s == token {
this.separators.Push(token)
continue outer
}
}
for _, o := range operators {
if o == token {
this.operators.Push(token)
continue outer
}
}
//check if literal
_, err := strconv.Atof(token)
if err == nil {
this.literals.Push(token)
continue outer
}
//if it reaches here, then it is an identifier
this.identifiers.Push(token)
}
}
示例4: FitnessAndQuality
// Find the best match for a given mime-type against
// a list of media_ranges that have already been
// parsed by ParseMediaRange(). Returns a tuple of
// the fitness value and the value of the 'q' quality
// parameter of the best match, or (-1, 0) if no match
// was found. Just as for QualityParsed(), 'parsedranges'
// must be a list of parsed media ranges.
func FitnessAndQuality(mimetype string, parsedRanges []Mime) (fitness int, quality float) {
bestfitness := -1
bestquality := 0.0
target, _ := ParseMediaRange(mimetype)
for _, r := range parsedRanges {
pmatches := 0
fitness := 0
if (r.mtype == target.mtype || r.mtype == "*" || target.mtype == "*") &&
(r.subtype == target.subtype || r.subtype == "*" || target.subtype == "*") {
fitness += 1
for key, targetvalue := range target.params {
if key != "q" {
if value, ok := r.params[key]; ok && value == targetvalue {
pmatches++
}
}
}
fitness += pmatches
if r.subtype == target.subtype {
fitness += 10
}
if r.mtype == target.mtype {
fitness += 100
}
if fitness > bestfitness {
bestfitness = fitness
bestquality, _ = strconv.Atof(r.params["q"])
}
}
}
return bestfitness, bestquality
}
示例5: F
func (this *Section) F(key string, defval float) float {
if v, ok := this.Pairs[key]; ok {
if f, err := strconv.Atof(v); err == nil {
return f
}
}
return defval
}
示例6: GetFloat
// GetFloat has the same behaviour as GetString but converts the response to float.
func (c *ConfigFile) GetFloat(section string, option string) (value float, err os.Error) {
sv, err := c.GetString(section, option)
if err == nil {
value, err = strconv.Atof(sv)
}
return value, err
}
示例7: parse1Param
// Parsuje parametr znajdujacy sie na poczatku frag. Pomija biale znaki przed
// parametrem i usuwa za nim (po wywolaniu frag[0] nie jest bialym znakiem).
func parse1Param(txt *string, lnum *int) (
par interface{}, err os.Error) {
frag := *txt
// Pomijamy biale znaki, ktore moga wystapic przed parametrem.
err = skipWhite(&frag, lnum)
if err != nil {
return
}
if frag[0] == '"' || frag[0] == '\'' {
// Parametrem jest tekst.
txt_sep := frag[0:1]
frag = frag[1:]
if len(frag) == 0 {
err = ParseErr{*lnum, PARSE_UNEXP_EOF}
return
}
// Parsujemy tekst parametru.
par, err = parse1(&frag, lnum, txt_sep)
if err != nil {
return
}
} else if uni.IsDigit(int(frag[0])) ||
str.IndexRune(seps_num, int(frag[0])) != -1 {
// Parametrem jest liczba
ii := findChar(frag, seps_nnum, lnum)
if ii == -1 {
err = ParseErr{*lnum, PARSE_UNEXP_EOF}
return
}
var iv int
iv, err = strconv.Atoi(frag[0:ii])
if err != nil {
var fv float
fv, err = strconv.Atof(frag[0:ii])
if err != nil {
err = ParseErr{*lnum, PARSE_BAD_FLOINT}
return
}
par = reflect.NewValue(fv)
} else {
par = reflect.NewValue(iv)
}
frag = frag[ii:]
} else {
par, err = parse1VarFun("", &frag, lnum, false)
if err != nil {
return
}
}
// Pomijamy biale znaki, ktore moga wystapic po parametrze.
err = skipWhite(&frag, lnum)
*txt = frag
return
}
示例8: LoadXML
func (d DoubleValue) LoadXML(p *xml.Parser) (ParamValue, os.Error) {
val, er := readBody(p)
if er != nil {
return nil, er
}
tempDouble, err := strconv.Atof(val)
d = DoubleValue(tempDouble)
return d, err
}
示例9: ParseMediaRange
// Carves up a media range and returns a tuple of the
// (type, subtype, params) where 'params' is a dictionary
// of all the parameters for the media range.
// For example, the media range 'application/*;q=0.5' would
// get parsed into:
//
// ('application', '*', {'q', '0.5'})
//
// In addition this function also guarantees that there
// is a value for 'q' in the params dictionary, filling it
// in with a proper default if necessary.
func ParseMediaRange(mediarange string) (mime Mime, err os.Error) {
parsed, err := ParseMimeType(mediarange)
if err != nil {
return parsed, err
}
if q, ok := parsed.params["q"]; ok {
if val, err := strconv.Atof(q); err != nil || val > 1.0 || val < 0.0 {
parsed.params["q"] = "1"
}
} else {
parsed.params["q"] = "1"
}
return parsed, nil
}
示例10: readFloat
func readFloat(r io.Reader) (float, os.Error) {
bits, err := ioutil.ReadAll(io.LimitReader(r, 31))
if err != nil {
return 0, err
}
// Atof doesn't like trailing 0s
var i int
for i = 0; i < len(bits); i++ {
if bits[i] == 0 {
break
}
}
return strconv.Atof(string(bits[0:i]))
}
示例11: f_numify
func f_numify(v *Any) *Any {
switch i := (*v).(type) {
case nil:
return i_0
case Undef:
return i_0
case Int:
return v
case Num:
return v
case Str:
// Str can be converted to Int or Num
s := string((*v).(Str))
out := ""
pos := 0
max := len(s)
if pos >= max {
return i_0
}
if s[pos] == '+' {
pos++
} else if s[pos] == '-' {
out += s[pos : pos+1]
pos++
}
if pos >= max || s[pos] < '0' || s[pos] > '9' {
return i_0
}
for i := pos; i < len(s); i++ {
if s[i] >= '0' && s[i] <= '9' {
out += s[i : i+1]
pos++
} else {
i = len(s)
}
}
if (pos < max && s[pos] == '.') || ((pos+1) < max && (s[pos] == 'e' || s[pos] == 'E') && (s[pos+1] == '+' || s[pos+1] == '-' || (s[pos+1] >= '0' && s[pos+1] <= '9'))) {
// 123. 123e10
n, _ := strconv.Atof(s)
return toNum(n)
}
n, _ := strconv.Atoi(out)
return toInt(n)
}
return (*v).(int_er).f_int(Capture{})
}
示例12: getFactor
// Find and evaluate a factor
func getFactor() float {
if digitCheck, _ := regexp.MatchString("[0-9]+(\\.[0-9]+)?", input[0]); digitCheck {
res, _ := strconv.Atof(input[0])
pop()
return res
} else if input[0] == "(" {
pop()
res := getExpr()
if input[0] != ")" {
doerror("No closing parenthesis")
}
pop()
return res
} else {
doerror(fmt.Sprintf("Misplaced element %s, check syntax", input[0]))
}
return 0
}
示例13: processRow
func processRow(row string) (d StockData, err os.Error) {
rowParts := strings.Split(row, ",", -1)
d.date = rowParts[0]
var tmp float
tmp, err = strconv.Atof(rowParts[4])
if err != nil {
return
}
d.close = tmp
var tmpInt int
tmpInt, err = strconv.Atoi(rowParts[5])
if err != nil {
return
}
d.volume = tmpInt
return d, nil
}
示例14: set
func (f *floatValue) set(s string) bool {
v, err := strconv.Atof(s)
*f.p = v
return err == nil
}
示例15: Set
func (f *floatValue) Set(s string) bool {
v, err := strconv.Atof(s)
*f = floatValue(v)
return err == nil
}