当前位置: 首页>>代码示例>>Golang>>正文


Golang strconv.Atof函数代码示例

本文整理汇总了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");
}
开发者ID:gyuque,项目名称:shadergo,代码行数:35,代码来源:main.go

示例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")
}
开发者ID:sim82,项目名称:go_tools,代码行数:26,代码来源:tree_parser.go

示例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)
	}
}
开发者ID:abiosoft,项目名称:lexicon,代码行数:34,代码来源:lexer.go

示例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
}
开发者ID:laiello,项目名称:mimeparse,代码行数:40,代码来源:mimeparse.go

示例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
}
开发者ID:welterde,项目名称:go-pkg-ini,代码行数:8,代码来源:section.go

示例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
}
开发者ID:GoogleSourceExpoted,项目名称:goesmtp,代码行数:9,代码来源:configfile.go

示例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
}
开发者ID:strogo,项目名称:kasia.go,代码行数:60,代码来源:parser1.go

示例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
}
开发者ID:sionide21,项目名称:Go-xml-rpc,代码行数:9,代码来源:common.go

示例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
}
开发者ID:laiello,项目名称:mimeparse,代码行数:25,代码来源:mimeparse.go

示例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]))
}
开发者ID:wjessop,项目名称:gobert,代码行数:16,代码来源:decode.go

示例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{})
}
开发者ID:sombr,项目名称:Perlito,代码行数:46,代码来源:Runtime.go

示例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
}
开发者ID:qrush,项目名称:go,代码行数:19,代码来源:expr.go

示例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
}
开发者ID:SnertSnert,项目名称:turbulentflyer,代码行数:20,代码来源:Common.go

示例14: set

func (f *floatValue) set(s string) bool {
	v, err := strconv.Atof(s)
	*f.p = v
	return err == nil
}
开发者ID:cemeyer,项目名称:gognuflag-deadproject,代码行数:5,代码来源:gnuflag.go

示例15: Set

func (f *floatValue) Set(s string) bool {
	v, err := strconv.Atof(s)
	*f = floatValue(v)
	return err == nil
}
开发者ID:rapgamer,项目名称:golang-china,代码行数:5,代码来源:flag.go


注:本文中的strconv.Atof函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。