本文整理汇总了Golang中math.Modf函数的典型用法代码示例。如果您正苦于以下问题:Golang Modf函数的具体用法?Golang Modf怎么用?Golang Modf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Modf函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestEarth2
func TestEarth2(t *testing.T) {
// p. 274
v, err := pp.LoadPlanet(pp.Earth)
if err != nil {
t.Fatal(err)
}
for _, d := range ep {
yf := float64(d.y) + (float64(d.m)-.5)/12
u, r := pa.Perihelion2(pa.Earth, yf, .0004, v)
y, m, df := julian.JDToCalendar(u)
dd, f := math.Modf(df)
if y != d.y || m != d.m || int(dd) != d.d ||
math.Abs(f*24-d.h) > .01 ||
math.Abs(r-d.r) > .000001 {
t.Log(d)
t.Fatal(y, m, int(dd), f*24, r)
}
}
for _, d := range ea {
yf := float64(d.y) + (float64(d.m)-.5)/12
u, r := pa.Aphelion2(pa.Earth, yf, .0004, v)
y, m, df := julian.JDToCalendar(u)
dd, f := math.Modf(df)
if y != d.y || m != d.m || int(dd) != d.d ||
math.Abs(f*24-d.h) > .01 ||
math.Abs(r-d.r) > .000001 {
t.Log(d)
t.Fatal(y, m, int(dd), f*24, r)
}
}
}
示例2: Medium
/*
Medium returns a map of New Zealand at medium resolution. The underlying longitude latitude grid is in 0.1
increments. Linear interpolation is used between grid points to estimate the location of each Point on the map.
*/
func (pts Points) Medium(b *bytes.Buffer) {
b.WriteString(nzMedium)
// the long/lat grid is accurate to 0.1 degree below that use a linear approximation between
// the grid values. This removes liniations in the plot
var p, pp pt
for i, v := range pts {
if v.Longitude < 0 {
v.Longitude = v.Longitude + 360.0
}
xi, xf := math.Modf(v.Longitude*10 - 1650.0)
x := int(xi)
yi, yf := math.Modf(v.Latitude*10 + 480.0)
y := int(yi)
if x >= 0 && x <= 150 && y >= 0 && y <= 140 {
p = nzMediumPts[int(x)][y]
pp = nzMediumPts[x+1][y+1]
pts[i].x = p.x + int(float64(pp.x-p.x)*xf)
pts[i].y = p.y + int(float64(pp.y-p.y)*yf)
pts[i].visible = true
} else {
pts[i].x = -1000
pts[i].y = -1000
}
}
return
}
示例3: processAudio
func (g *stereoSine) processAudio(out [][]float32) {
for i := range out[0] {
val1 := g.volume * math.Sin(2*math.Pi*g.phase1)
val2 := g.volume * math.Sin(2*math.Pi*g.phase2)
val1l := math.Max(val1*g.pan1, 0) * 0.5
val2l := math.Max(val2*g.pan2, 0) * 0.5
val1r := math.Max(val1*-g.pan1, 0) * 0.5
val2r := math.Max(val2*-g.pan2, 0) * 0.5
out[0][i] = float32(val1l + val2l)
out[1][i] = float32(val1r + val2r)
_, g.phase1 = math.Modf(g.phase1 + g.step1)
_, g.phase2 = math.Modf(g.phase2 + g.step2)
g.volume += g.fade
if g.volume < 0 {
g.volume = 0
g.fade = 0
g.control <- true
}
if g.volume > 1 {
g.volume = 1
g.fade = 0
g.control <- true
}
}
}
示例4: generateRandomNetwork
func generateRandomNetwork(address *net.IPNet) string {
tick := float64(time.Now().UnixNano() / 1000000)
ones, bits := address.Mask.Size()
zeros := bits - ones
uniqIPsAmount := math.Pow(2.0, float64(zeros))
rawIP := math.Mod(tick, uniqIPsAmount)
remainder := rawIP
remainder, octet4 := math.Modf(remainder / 255.0)
remainder, octet3 := math.Modf(remainder / 255.0)
remainder, octet2 := math.Modf(remainder / 255.0)
base := address.IP
address.IP = net.IPv4(
byte(remainder)|base[0],
byte(octet2*255)|base[1],
byte(octet3*255)|base[2],
byte(octet4*255)|base[3],
)
address.IP.Mask(address.Mask)
return address.String()
}
示例5: LatLongToString
func LatLongToString(pc *PolarCoord, format LatLongFormat) (string, string) {
var lat, long, latrem, longrem, latmin, longmin, latsec, longsec float64
var latitude, longitude string
switch format {
case LLFdeg:
latitude = f64toa(pc.Latitude, 6)
longitude = f64toa(pc.Longitude, 6)
case LLFdms:
lat, latrem = math.Modf(pc.Latitude)
if lat < 0 {
lat *= -1
latrem *= -1
}
long, longrem = math.Modf(pc.Longitude)
if long < 0 {
long *= -1
longrem *= -1
}
latmin, latrem = math.Modf(latrem / 100 * 6000)
longmin, longrem = math.Modf(longrem / 100 * 6000)
latsec = latrem / 100 * 6000
longsec = longrem / 100 * 6000
if pc.Latitude < 0 {
latitude = "S "
} else {
latitude = "N "
}
latitude += fmt.Sprintf("%d°", int(lat))
if latmin != 0.0 || latsec != 0.0 {
latitude += fmt.Sprintf("%d'", int(latmin))
}
if latsec != 0.0 {
latitude += fmt.Sprintf("%s''", f64toa(latsec, 2))
}
if pc.Longitude < 0 {
longitude = "W "
} else {
longitude = "E "
}
longitude += fmt.Sprintf("%d°", int(long))
if longmin != 0.0 || longsec != 0.0 {
longitude += fmt.Sprintf("%d'", int(longmin))
}
if longsec != 0.0 {
longitude += fmt.Sprintf("%s''", f64toa(longsec, 2))
}
}
return latitude, longitude
}
示例6: ProcessAudio
// ProcessAudio processes the audio
func (sine *Sine) ProcessAudio(out [][2]float32) {
for i := range out {
out[i][0] = float32(math.Sin(2 * math.Pi * sine.phaseL))
_, sine.phaseL = math.Modf(sine.phaseL + sine.stepL)
out[i][1] = float32(math.Sin(2 * math.Pi * sine.phaseR))
_, sine.phaseR = math.Modf(sine.phaseR + sine.stepR)
}
}
示例7: processAudio
func (g *stereoSine) processAudio(out [][]float32) {
for i := range out[0] {
out[0][i] = float32(math.Sin(2 * math.Pi * g.phaseL))
_, g.phaseL = math.Modf(g.phaseL + g.stepL)
out[1][i] = float32(math.Sin(2 * math.Pi * g.phaseR))
_, g.phaseR = math.Modf(g.phaseR + g.stepR)
}
}
示例8: GetChunkCoords
func GetChunkCoords(x float32, y float32) (float32, float32) {
chunkSize := float64(100)
xRoot, _ := math.Modf(float64(x) / chunkSize)
yRoot, _ := math.Modf(float64(y) / chunkSize)
return float32(xRoot * chunkSize), float32(yRoot * chunkSize)
}
示例9: julianDateToGregorianTime
func julianDateToGregorianTime(part1, part2 float64) time.Time {
part1I, part1F := math.Modf(part1)
part2I, part2F := math.Modf(part2)
julianDays := part1I + part2I
julianFraction := part1F + part2F
julianDays, julianFraction = shiftJulianToNoon(julianDays, julianFraction)
day, month, year := doTheFliegelAndVanFlandernAlgorithm(int(julianDays))
hours, minutes, seconds, nanoseconds := fractionOfADay(julianFraction)
return time.Date(year, time.Month(month), day, hours, minutes, seconds, nanoseconds, time.UTC)
}
示例10: durationToSQL
// durationToSQL converts a time.Duration to ISO standard SQL syntax,
// e.g. "1 2:3:4" for one day, two hours, three minutes, and four seconds.
func durationToSQL(d time.Duration) []byte {
dSeconds := d.Seconds()
dMinutes, fSeconds := math.Modf(dSeconds / 60)
seconds := fSeconds * 60
dHours, fMinutes := math.Modf(dMinutes / 60)
minutes := fMinutes * 60
days, fHours := math.Modf(dHours / 24)
hours := fHours * 24
sql := fmt.Sprintf("%.0f %.0f:%.0f:%f", days, hours, minutes, seconds)
return []byte(sql)
}
示例11: processAudio
func (g *stereoSine) processAudio(out [][]float32) {
var t float64 = 0
for i := range out[0] {
out[0][i] = float32(math.Sin(2*math.Pi*g.phaseL*(t/float64(bpm)))) / 2
//out[0][i] = float32(math.Sin(2 * math.Pi * float64(tcp%400) * (t / float64(bpm))))
_, g.phaseL = math.Modf(g.phaseL + g.stepL)
out[1][i] = float32(math.Sin(2*math.Pi*g.phaseR*(t/float64(bpm)))) / 2
//out[1][i] = float32(math.Sin(2 * math.Pi * float64(tcp%400) * (t / float64(bpm))))
_, g.phaseR = math.Modf(g.phaseR + g.stepR)
t++
}
}
示例12: NumberFormat
// NumberFormat convert float or int to string (like PHP number_format() )
// in local format, for example:
// NumberFormat( 123456.12, 4, ",", " " )
// >> 123 456,1200
//
// Special cases are:
// NumberFormat(±Inf) = formatted 0.0
// NumberFormat(NaN) = formatted 0.0
func NumberFormat(number float64, decimals int, decPoint, thousandsSep string) string {
if math.IsNaN(number) || math.IsInf(number, 0) {
number = 0
}
var ret string
var negative bool
if number < 0 {
number *= -1
negative = true
}
d, fract := math.Modf(number)
if decimals <= 0 {
fract = 0
} else {
pow := math.Pow(10, float64(decimals))
fract = RoundPrec(fract*pow, 0)
}
if thousandsSep == "" {
ret = strconv.FormatFloat(d, 'f', 0, 64)
} else if d >= 1 {
var x float64
for d >= 1 {
d, x = math.Modf(d / 1000)
x = x * 1000
ret = strconv.FormatFloat(x, 'f', 0, 64) + ret
if d >= 1 {
ret = thousandsSep + ret
}
}
} else {
ret = "0"
}
fracts := strconv.FormatFloat(fract, 'f', 0, 64)
// "0" pad left
for i := len(fracts); i < decimals; i++ {
fracts = "0" + fracts
}
ret += decPoint + fracts
if negative {
ret = "-" + ret
}
return ret
}
示例13: RandBetweenFloat
// 范围随机数 float64
// 只随机精度的值,随机精度范围[0.x... -- 0.x...]
func RandBetweenFloat(s, n float64) float64 {
if s > n {
s, n = n, s
}
_, sFrac := math.Modf(s)
_, nFrac := math.Modf(n)
mathrand.Seed(time.Now().UnixNano())
rf := float64(mathrand.Int63()) / (1 << 63)
rf = sFrac + rf*(nFrac-sFrac)
return rf
}
示例14: CastRay
func (me *renderTile) CastRay(x, y int, col *color.RGBA) {
me.fx, me.fy = float64(x), float64(y)
col.R, col.G, col.B, col.A = 0, 0, 0, 0
me.rayPos.X, me.rayPos.Y, me.rayPos.Z = ((me.fx / width) - 0.5), ((me.fy / height) - 0.5), 0
me.rayPos.MultMat(cmat1)
me.rayTmp.X, me.rayTmp.Y, me.rayTmp.Z = 0, 0, planeDist
me.rayTmp.MultMat(cmat1)
// if (CamRot.Y != 0) && ((x == 0) || (x == 39) || (x == 79) || (x == 119) || (x == 159)) && ((y == 0) || (y == 44) || (y == 89)) { log.Printf("[%v,%v] 0,0,%v ==> %+v (for %+v)", x, y, planeDist, me.rayTmp, me.rayDir) }
me.rayDir.X, me.rayDir.Y, me.rayDir.Z = me.rayPos.X, me.rayPos.Y, me.rayPos.Z-me.rayTmp.Z
me.rayDir.Normalize()
me.rayDir.MultMat(pmat)
me.rayPos.Add(CamPos)
// me.rayDir.X, me.rayDir.Y, me.rayDir.Z = -((me.fx / width) - 0.5), -((me.fy / height) - 0.5), planeDist
if true {
// if ((x == 0) || (x == 159)) && ((y == 0) || (y == 89)) { log.Printf("RAYPOS[%v,%v]=%+v", x, y, me.rayPos) }
me.numSteps = 0
for (col.A < 255) && me.rayPos.AllInRange(vmin, vmax) && (me.numSteps <= (vboth)) {
me.numSteps++
if me.rayPos.AllInRange(0, fs) {
if col.A == 0 {
if (int(me.rayPos.X) == 0) || (int(me.rayPos.X) == (SceneSize - 1)) {
col.R, col.G, col.B, col.A = 0, 0, 64, 64
} else if (int(me.rayPos.Y) == 0) || (int(me.rayPos.Y) == (SceneSize - 1)) {
col.R, col.G, col.B, col.A = 0, 64, 0, 64
} else {
col.R, col.G, col.B, col.A = 32, 32, 32, 48
}
}
if samples {
_, me.fracx = math.Modf(me.rayPos.X)
_, me.fracy = math.Modf(me.rayPos.Y)
_, me.fracz = math.Modf(me.rayPos.Z)
me.rayIntX, me.rayIntY, me.rayIntZ = int(me.rayPos.X), int(me.rayPos.Y), int(me.rayPos.Z)
me.lrayIntX, me.lrayIntY, me.lrayIntZ = int(me.rayPos.X+1), int(me.rayPos.Y+1), int(me.rayPos.Z+1)
me.getSample(me.rayIntX, me.rayIntY, me.rayIntZ, col)
me.getSample(me.lrayIntX, me.rayIntY, me.rayIntZ, &me.colx)
me.getSample(me.rayIntX, me.lrayIntY, me.rayIntZ, &me.coly)
me.getSample(me.rayIntX, me.rayIntY, me.lrayIntZ, &me.colz)
//me.mixAll()
} else {
me.rayIntX, me.rayIntY, me.rayIntZ = int(me.rayPos.X), int(me.rayPos.Y), int(me.rayPos.Z)
me.getSample(me.rayIntX, me.rayIntY, me.rayIntZ, col)
}
}
me.rayPos.Add(me.rayDir)
}
}
}
示例15: preComputeFilter
func preComputeFilter(scale float64,
outSize, srcSize int,
scaleBpp float64) []filter {
ret := make([]filter, outSize)
// The minimum worthwhile fraction of a pixel. This value is also used
// to avoid direct floating-point comparisons; instead of comparing two
// values for equality, we test if their difference is smaller than this
// value.
const minFrac = 1.0 / 256.0
for i := 0; i < outSize; i++ {
// compute the address and first weight
addr, invw := math.Modf(float64(i) * scale)
ret[i].idx = int(addr)
frstw := 1.0 - invw
if frstw < minFrac {
ret[i].idx++
frstw = 0.0
} else {
ret[i].n = 1
}
// compute the number of pixels
count, frac := math.Modf(scale - frstw)
ret[i].n = ret[i].n + int(count)
if frac >= minFrac {
ret[i].n++
} else {
frac = 0.0
}
// allocate the slice of weights
ret[i].weights = make([]float64, ret[i].n)
var windx int
if frstw > 0.0 {
ret[i].weights[windx] = frstw / scale * scaleBpp
windx++
}
for j := 0; j < int(count); j++ {
ret[i].weights[windx] = 1.0 / scale * scaleBpp
windx++
}
if frac > 0.0 {
ret[i].weights[windx] = frac / scale * scaleBpp
}
}
return ret
}