當前位置: 首頁>>代碼示例>>Golang>>正文


Golang flag.Float64函數代碼示例

本文整理匯總了Golang中flag.Float64函數的典型用法代碼示例。如果您正苦於以下問題:Golang Float64函數的具體用法?Golang Float64怎麽用?Golang Float64使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Float64函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: main

func main() {
	maxSideLength := flag.Float64("max", 1, "maximum side length")
	minSideLength := flag.Float64("min", 1, "minimum side length")
	flag.Parse()

	cuboidStream := make(chan Cuboid, NUM_CONCURRENT_CUBOID_SEARCHES)
	perfectCuboid := make(chan Cuboid)
	wg := new(sync.WaitGroup)

	go waitForPerfectCuboid(perfectCuboid)
	go distributeCuboids(cuboidStream, perfectCuboid, wg)

	fmt.Printf("Searching for a perfect cuboid with side lengths between %d and %d...", int(*minSideLength), int(*maxSideLength))

	x := 1.0
	for x <= *maxSideLength {
		y := 1.0
		for y <= *maxSideLength {
			z := 1.0
			for z <= *maxSideLength {
				if x >= *minSideLength || y >= *minSideLength || z >= *minSideLength {
					wg.Add(1)
					cuboid := Cuboid{Length: x, Width: y, Height: z}
					cuboidStream <- cuboid
				}
				z += 1
			}
			y += 1
		}
		x += 1
	}

	wg.Wait()
	fmt.Println(" done.")
}
開發者ID:kochman,項目名稱:perfectcuboid,代碼行數:35,代碼來源:perfectcuboid.go

示例2: main

func main() {
	debug := flag.Bool("debug", false, "debug on")
	threaded := flag.Bool("threaded", true, "debug on")
	delcache_ttl := flag.Float64("deletion_cache_ttl", 5.0, "Deletion cache TTL in seconds.")
	branchcache_ttl := flag.Float64("branchcache_ttl", 5.0, "Branch cache TTL in seconds.")
	deldirname := flag.String(
		"deletion_dirname", "GOUNIONFS_DELETIONS", "Directory name to use for deletions.")
	flag.Parse()

	if len(flag.Args()) < 2 {
		fmt.Println("Usage:\n  main MOUNTPOINT RW-DIRECTORY RO-DIRECTORY ...")
		os.Exit(2)
	}

	ufsOptions := unionfs.UnionFsOptions{
		DeletionCacheTTLSecs: *delcache_ttl,
		BranchCacheTTLSecs:   *branchcache_ttl,
		DeletionDirName:      *deldirname,
	}

	ufs, err := unionfs.NewUnionFsFromRoots(flag.Args()[1:], &ufsOptions)
	if err != nil {
		log.Fatal("Cannot create UnionFs", err)
		os.Exit(1)
	}
	mountState, _, err := fuse.MountFileSystem(flag.Arg(0), ufs, nil)
	if err != nil {
		log.Fatal("Mount fail:", err)
	}

	mountState.Debug = *debug
	mountState.Loop(*threaded)
}
開發者ID:jravasi,項目名稱:go-fuse,代碼行數:33,代碼來源:main.go

示例3: main

func main() {

	// Set up flags.
	wFlag := flag.Int("w", 640, "width of the image in pixels")
	hFlag := flag.Int("h", 480, "height of the image in pixels")
	xMinFlag := flag.Float64("x-min", -2.0, "minimum x value to plot")
	xMaxFlag := flag.Float64("x-max", 2.0, "maximum x value to plot")
	bailoutFlag := flag.Int("bailout", 100, "maximum iteration bailout")

	// Handle the flags.
	flag.Parse()

	// Main logic.
	acc := newAccumulator(*wFlag, *hFlag, *xMinFlag, *xMaxFlag)
	const numSamples = 1e8
	for acc.getCount() < numSamples {
		log.Print(acc.getCount())
		accumulateSeqence(*bailoutFlag, acc)
	}

	img := acc.toImage()
	f, err := os.Create("out.png")
	if err != nil {
		log.Fatal(err)
	}
	if err := png.Encode(f, img); err != nil {
		log.Fatal(err)
	}
}
開發者ID:peterstace,項目名稱:buddhabrotgen,代碼行數:29,代碼來源:main.go

示例4: main

func main() {
	drinks := flag.Float64("drinks", 2.5, "How many drinks consumed")
	weight := flag.Float64("weight", 70.0, "Body weight in kilograms")
	hours := flag.Float64("hours", 2.0, "How many hours it took to drink")
	gender := flag.String("gender", "male", "Specify male or female")

	flag.Usage = func() {
		fmt.Println(`
  NAME:

    inebriati

  DESCRIPTION:

    Calculates estimated blood ethanol concentration (EBAC) 

  COMMANDS:

    -drinks              Number of standard drinks comsumed.
    -weight              Weight in kiligrams.
    -hours               Drinking period in hours.
    -gender              Select male or female.
`[1:])
	}

	flag.Parse()

	i := inebriati.New(*drinks, *weight, *hours, *gender)
	i.Calc()

	fmt.Println(i)
}
開發者ID:NovemberFoxtrot,項目名稱:inebriati,代碼行數:32,代碼來源:tippler.go

示例5: main

func main() {
	size := flag.Int("psize", 500, "physical size of the square image")
	vpx := flag.Float64("x", 0, "x coordinate of the center of the image")
	vpy := flag.Float64("y", 0, "y coordinate of the center of the image")
	d := flag.Float64("size", 2, "size of the represented part of the plane")
	filename := flag.String("name", "image", "name of the image file produced (w/o extension")
	numberOfProcs := flag.Int("procs", 2, "number of procs to use")
	seed := flag.Int64("seed", 42, "seed for the random number generator")
	cols := flag.Bool("with-colors", false, "whether there is colors")

	flag.Parse()

	runtime.GOMAXPROCS(*numberOfProcs)

	withColors = *cols
	if *cols {
		initColors(*seed)
	}

	file, err := os.Open(*filename+".png", os.O_RDWR|os.O_CREAT, 0666)
	if err != nil {
		panic("error with opening file \"" + *filename + "\"")
	}

	im := image.NewRGBA(*size, *size)

	ch := make(chan point, 1000)

	Start(im, 2, *vpx, *vpy, *d, ch)

	handleChans(im, ch)

	png.Encode(file, im)
}
開發者ID:ineol,項目名稱:mandelgo,代碼行數:34,代碼來源:mandel.go

示例6: handleAddConsumer

func handleAddConsumer() error {
	id := stripArgument()
	if id == "" {
		return errors.New("No task id supplied to add")
	}
	var (
		api = flag.String("api", "", "API host:port")
		cpu = flag.Float64("cpu", 0.1, "CPUs per task")
		mem = flag.Float64("mem", 128, "Mem per task")
	)
	ParseFlags("add")
	if err := resolveApi(*api); err != nil {
		return err
	}

	if *executor == "" {
		return errors.New("Executor name required")
	}

	request := framework.NewApiRequest(framework.Config.Api + "/api/add")
	request.PutString("type", framework.TaskTypeConsumer)
	request.PutString("id", id)
	request.PutFloat("cpu", *cpu)
	request.PutFloat("mem", *mem)
	request.PutString("executor", *executor)

	response := request.Get()

	fmt.Println(response.Message)

	return nil
}
開發者ID:elodina,項目名稱:go-kafka-client-mesos,代碼行數:32,代碼來源:cli.go

示例7: main

func main() {
	diameter := flag.Float64("d", 9.0, "beam diameter in millimetres")
	power := flag.Float64("p", 1.0, "laser power in watts")
	flag.Parse()

	if *diameter <= 0.0 {
		fmt.Println("Beam diameter must be a positive number greater than zero.")
		return
	}

	*diameter /= 1000.0 // convert mm to m
	ba := beamArea(*diameter)
	pd := powerDensity(ba, *power)
	od := opticalDensity(pd)
	fmt.Printf("Beam area: %f m^2\nPower density: %f W/m^2\n", ba, pd)
	if od == -1 {
		fmt.Println("Couldn't determine the appropriate optical density rating.")
		fmt.Println("Please consult EN207 for the appopriate PPE.")
	} else if od == 11 {
		fmt.Printf("Your optical density requirements are above the ")
		fmt.Printf("standard requirements. Please consult EN207.\n")
	} else {
		fmt.Printf("Based on your laser's power and beam diameter, ")
		fmt.Printf("you should use eyewear with an OD of %d.\n", od)
	}
}
開發者ID:kisom,項目名稱:laserod,代碼行數:26,代碼來源:od.go

示例8: main

func main() {

	var data = flag.String("data", "", "The data directory where WOF data lives, required")
	var cache_size = flag.Int("cache_size", 1024, "The number of WOF records with large geometries to cache")
	var cache_trigger = flag.Int("cache_trigger", 2000, "The minimum number of coordinates in a WOF record that will trigger caching")

	var lat = flag.Float64("latitude", 0.0, "")
	var lon = flag.Float64("longitude", 0.0, "")

	var loglevel = flag.String("loglevel", "info", "...")

	flag.Parse()

	logger := log.NewWOFLogger("[wof-breaches] ")
	logger.AddLogger(os.Stdout, *loglevel)

	idx, _ := rtree.NewIndex(*data, *cache_size, *cache_trigger, logger)

	for _, path := range flag.Args() {

		logger.Info("indexing %s", path)
		idx.IndexGeoJSONFile(path)
	}

	results := idx.GetIntersectsByLatLon(*lat, *lon)
	inflated := idx.InflateSpatialResults(results)

	for _, r := range inflated {
		logger.Info("%v", r)
	}
}
開發者ID:whosonfirst,項目名稱:go-whosonfirst-rtree,代碼行數:31,代碼來源:wof-rtree-pip.go

示例9: main

func main() {
	// do the actual parsing
	flag.Var(&listenersFlag, "l", "Which ports to listen on")
	flag.Var(&connectorsFlag, "c", "Which addresses to try to connect to")
	flag.BoolVar(&infoptr, "v", false, "Turn on verbose mode")
	flag.BoolVar(&debugptr, "vv", false, "Turn on extra verbose mode")
	retryPeriod = time.Duration(1000 * (*flag.Float64("rp", 5.0,
		"Retry rate for double connections")))
	connPeriod = time.Duration(1000 * (*flag.Float64("cp", 0.5,
		"Retry rate for double connections, on success")))
	flag.Parse()

	debug("Number of listeners: " + fmt.Sprint(len(listenersFlag)))
	debug("Number of connectors: " + fmt.Sprint(len(connectorsFlag)))
	// check a possibly temporary condition
	if len(listenersFlag)+len(connectorsFlag) != 2 {
		errmsg(1, "Strictly 2 connections allowed")
	}

	if len(listenersFlag) == 1 && len(connectorsFlag) == 1 {
		listenOne(normalizeAddr(listenersFlag[0]),
			normalizeAddr(connectorsFlag[0]))
	}
	if len(listenersFlag) == 2 && len(connectorsFlag) == 0 {
		listenTwo(normalizeAddr(listenersFlag[0]),
			normalizeAddr(listenersFlag[1]))
	}
	if len(listenersFlag) == 0 && len(connectorsFlag) == 2 {
		connectTwo(normalizeAddr(connectorsFlag[0]),
			normalizeAddr(connectorsFlag[1]))
	}
}
開發者ID:thenoviceoof,項目名稱:proxybfs,代碼行數:32,代碼來源:proxybfs.go

示例10: main

func main() {
	count := flag.Int("count", 5, "The number of pings to send")
	wait := flag.Float64("wait", 15, "The amount of time to wait for all pings to come back in seconds")
	interval := flag.Float64("interval", 2, "The interval to wait between pings in seconds")
	repeat := flag.Int("repeat", 30, "Repeat the whole process every x seconds")
	socket := flag.String("socket", "/tmp/ping-monitor.sock", "Unix socket to create/listen on")

	flag.Parse()

	if len(flag.Args()) < 1 {
		os.Stderr.WriteString("Must supply at least one IP address!\n")
		os.Exit(1)
	}

	h := &httpmetrics.Handler{
		Socket:     *socket,
		Registries: make(map[string]*metrics.Registry),
	}

	pi := &PingInfo{
		Count:      *count,
		Wait:       *wait,
		Interval:   *interval,
		Repeat:     *repeat,
		Hosts:      flag.Args(),
		Registries: &(h.Registries),
	}

	InitPing(pi)

	if err := h.CreateServer(); err != nil {
		panic(err)
	}
}
開發者ID:mehulsbhatt,項目名稱:gollector-monitors,代碼行數:34,代碼來源:main.go

示例11: TestParse_Global

func TestParse_Global(t *testing.T) {
	resetForTesting("")

	os.Setenv(envTestPrefix+"D", "EnvD")
	os.Setenv(envTestPrefix+"E", "true")
	os.Setenv(envTestPrefix+"F", "5.5")

	flagA := flag.Bool("a", false, "")
	flagB := flag.Float64("b", 0.0, "")
	flagC := flag.String("c", "", "")

	flagD := flag.String("d", "", "")
	flagE := flag.Bool("e", false, "")
	flagF := flag.Float64("f", 0.0, "")

	parse(t, "./testdata/global.ini", envTestPrefix)
	if !*flagA {
		t.Errorf("flagA found %v, expected true", *flagA)
	}
	if *flagB != 5.6 {
		t.Errorf("flagB found %v, expected 5.6", *flagB)
	}
	if *flagC != "Hello world" {
		t.Errorf("flagC found %v, expected 'Hello world'", *flagC)
	}
	if *flagD != "EnvD" {
		t.Errorf("flagD found %v, expected 'EnvD'", *flagD)
	}
	if !*flagE {
		t.Errorf("flagE found %v, expected true", *flagE)
	}
	if *flagF != 5.5 {
		t.Errorf("flagF found %v, expected 5.5", *flagF)
	}
}
開發者ID:ngdinhtoan,項目名稱:globalconf,代碼行數:35,代碼來源:globalconf_test.go

示例12: main

func main() {

	lat := flag.Float64("lat", 0, "latitude of occurrence")
	lng := flag.Float64("lng", 0, "longitude of occurrence")
	explain := flag.Bool("explain", true, "print useful information")
	date := flag.Int64("date", 0, "unix second: 1467558491")
	period := flag.Int64("period", 14, "number of days into the past to generate weather: 14")

	flag.Parse()

	store, err := noaa.NewWeatherStore(
		"/Users/mph/Desktop/phenograph-raw-data/stations.txt",
		"/Users/mph/Desktop/phenograph-raw-data/ghcnd_all/ghcnd_all",
		false,
	)
	if err != nil {
		panic(err)
	}

	records, err := store.Nearest(
		*lat,
		*lng,
		noaa.Elements{noaa.ElementTMAX, noaa.ElementPRCP, noaa.ElementTMIN},
		noaa.TimesFromUnixArray(*date, *period),
		*explain,
	)
	if err != nil {
		panic(err)
	}

	fmt.Println("RECORDS", utils.JsonOrSpew(records))

	return
}
開發者ID:heindl,項目名稱:raincollector,代碼行數:34,代碼來源:main.go

示例13: decodeRefArg

func decodeRefArg(name, typeName string) (interface{}, error) {
	switch strings.ToLower(typeName) {
	case "*bool":
		newValue := flag.Bool(name, app.DefaultBoolValue, name)
		return newValue, nil
	case "bool":
		newValue := flag.Bool(name, app.DefaultBoolValue, name)
		return *newValue, nil

	case "*string":
		newValue := flag.String(name, app.DefaultStringValue, name)
		return *newValue, nil
	case "string":
		newValue := flag.String(name, app.DefaultStringValue, name)
		return *newValue, nil

	case "*time.duration":
		newValue := flag.Duration(name, app.DefaultDurationValue, name)
		return *newValue, nil
	case "time.duration":
		newValue := flag.Duration(name, app.DefaultDurationValue, name)
		return *newValue, nil

	case "*float64":
		newValue := flag.Float64(name, app.DefaultFloat64Value, name)
		return *newValue, nil
	case "float64":
		newValue := flag.Float64(name, app.DefaultFloat64Value, name)
		return *newValue, nil

	case "*int":
		newValue := flag.Int(name, app.DefaultIntValue, name)
		return *newValue, nil
	case "int":
		newValue := flag.Int(name, app.DefaultIntValue, name)
		return *newValue, nil

	case "*int64":
		newValue := flag.Int64(name, app.DefaultInt64Value, name)
		return *newValue, nil
	case "int64":
		newValue := flag.Int64(name, app.DefaultInt64Value, name)
		return *newValue, nil

	case "*uint":
		newValue := flag.Uint(name, app.DefaultUIntValue, name)
		return *newValue, nil
	case "uint":
		newValue := flag.Uint(name, app.DefaultUIntValue, name)
		return *newValue, nil

	case "*uint64":
		newValue := flag.Uint64(name, app.DefaultUInt64Value, name)
		return *newValue, nil
	case "uint64":
		newValue := flag.Uint64(name, app.DefaultUInt64Value, name)
		return *newValue, nil
	}
	return nil, fmt.Errorf("unknow type %s for argument %s", typeName, name)
}
開發者ID:goatcms,項目名稱:goat-core,代碼行數:60,代碼來源:injector.go

示例14: main

func main() {
	var seq_file = flag.String("s", "", "Specify a file containing the sequence.")
	var rl = flag.Int("l", 100, "Read length.")
	var coverage = flag.Float64("c", 2.0, "Coverage")
	var error_rate = flag.Float64("e", 0.01, "Error rate.")
	flag.BoolVar(&Debug, "debug", false, "Turn on debug mode.")
	flag.Parse()
	read_len := int(*rl)
	if *seq_file != "" {
		if *coverage > 0 && read_len > 0 {
			idx := fmi.New(*seq_file)
			num_of_reads := int(*coverage * float64(idx.LEN) / float64(read_len))
			read_indices := make([]int, num_of_reads)
			the_read := make([]byte, read_len)
			var rand_pos int

			for i := 0; i < num_of_reads; i++ {
				rand_pos = int(rand_gen.Intn(int(idx.LEN - read_len)))
				if justN(rand_pos, int(read_len)) {
					i--
					continue
				}

				read_indices = idx.Repeat(rand_pos, read_len)
				var errors []int
				if int(rand_pos+read_len) >= len(fmi.SEQ) {
					panic("Read may be shorter than wanted.")
				}

				copy(the_read, fmi.SEQ[rand_pos:rand_pos+read_len])
				for k := 0; k < len(the_read); k++ {
					if rand_gen.Float64() < *error_rate {
						the_read[k] = random_error(the_read[k])
						errors = append(errors, k)
					}
				}
				if Debug {
					for j := 0; j < int(rand_pos); j++ {
						fmt.Printf(" ")
					}
				}
				fmt.Printf("%s %d ", the_read, len(read_indices))
				for j := 0; j < len(read_indices); j++ {
					fmt.Printf("%d ", read_indices[j])
				}
				fmt.Printf("%d", len(errors))
				for j := 0; j < len(errors); j++ {
					fmt.Printf(" %d", errors[j])
				}
				fmt.Println()
			}
		} else {
			idx := fmi.New(*seq_file)
			idx.Save(*seq_file)
		}
	} else {
		fmt.Println("Must provide sequence file")
	}
}
開發者ID:vtphan,項目名稱:fmi,代碼行數:59,代碼來源:generate_reads.go

示例15: main

func main() {
	var ohms = flag.Float64("r", 0, "ohms")
	var watts = flag.Float64("w", 0, "watts")
	var amps = flag.Float64("a", 0, "amps")
	var volts = flag.Float64("v", 0, "volts")
	flag.Parse()
	fmt.Printf("O: %f\tW: %f\tA: %f\tV: %f\n", *ohms, *watts, *amps, *volts)
}
開發者ID:mkandel,項目名稱:playing_with_go,代碼行數:8,代碼來源:ohms_law.go


注:本文中的flag.Float64函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。