예제 #1
1
파일: math.go 프로젝트: fishedee/fishgo
//绝对值转成浮点数
func toFloat64(d decimal.Decimal) float64 {
	result, ok := d.Float64()
	if !ok {
		// TODO
	}
	return result
}
예제 #2
0
//Decode is the inverse operation of Encode.
//Decode returns latitude, longitude, and whether or not they are both represented precisely as float64 types.
func Decode(bucket int64) (float64, float64, bool) {
	var latitudeUnshifted, longitudeUnshifted decimal.Decimal
	var latitude, longitude float64
	var err error
	var exact bool
	bucketString := strconv.FormatInt(bucket, 10)
	for len(bucketString) < 18 {
		bucketString = "0" + bucketString
	}

	latString, lonString := unzip(bucketString)
	latString = latString[0:3] + "." + latString[3:]
	lonString = lonString[0:3] + "." + lonString[3:]

	latitudeUnshifted, err = decimal.NewFromString(latString)
	longitudeUnshifted, err = decimal.NewFromString(lonString)
	if err != nil {
		fmt.Errorf("Error creating decimal from string")
	}
	latitudeUnshifted = latitudeUnshifted.Sub(decimal.NewFromFloat(90.0))
	longitudeUnshifted = longitudeUnshifted.Sub(decimal.NewFromFloat(180.0))
	latitude, exact = latitudeUnshifted.Float64()
	longitude, exact = longitudeUnshifted.Float64()
	return latitude, longitude, exact
}
예제 #3
0
파일: compute.go 프로젝트: gpahal/calc
func DecimalToString(res decimal.Decimal, min int32, max int32) string {
	if res.Cmp(decimal.New(10, min)) <= 0 || res.Cmp(decimal.New(10, max)) >= 0 {
		f, _ := res.Float64()
		return strconv.FormatFloat(f, 'G', -1, 64)
	}
	return res.String()
}
예제 #4
0
파일: operators.go 프로젝트: gpahal/calc
func ConvertToDecimalBinary(f func(float64, float64) float64, a decimal.Decimal, b decimal.Decimal) decimal.Decimal {
	aFloat, _ := a.Float64()
	bFloat, _ := b.Float64()

	return decimal.NewFromFloat(f(aFloat, bFloat))
}