Ejemplo n.º 1
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
}
Ejemplo n.º 2
0
func (sc *salaryCalculator) Calculate(grossSalary, dependentsQty decimal.Decimal) Salary {
	inss := sc.inss.Calculate(grossSalary)
	dependents := sc.depedents.Calculate(dependentsQty)
	irrfBase := grossSalary.Sub(inss).Sub(dependents)
	irrf := sc.irrf.Calculate(irrfBase)
	netSalary := grossSalary.Sub(inss).Sub(irrf)
	return Salary{
		GrossSalary: grossSalary,
		INSS:        inss,
		Dependents:  dependents,
		IRRF:        irrf,
		NetSalary:   netSalary,
	}
}
Ejemplo n.º 3
0
func newton(z, x decimal.Decimal) decimal.Decimal {
	return z.Sub(z.Mul(z).Sub(x).Div(Const2.Mul(z)))
}