Exemplo n.º 1
0
// ToInt64 returns the int64 value from a.
// The rounding passed as argument is used, instead of the rounding mode of context which is ignored.
//
func (context *Context) ToInt64(a Quad, rounding RoundingMode) int64 {
	var result C.Ret_int64_t
	assert_sane(context)

	result = C.mdq_to_int64(a.val, context.set, C.int(rounding))

	context.set = result.set
	return int64(result.val)
}
Exemplo n.º 2
0
// ToInt64 returns the int64 value from a.
// The rounding passed as argument is used, instead of the rounding mode of context which is ignored.
//
// The status field of a is not checked.
// If you need to check the status of a, you can call a.Error().
//
// Note that ToInt64 is slower than ToInt32, because the underlying C decNumber package has no function that converts directly to int64.
// So, the number is first converted to string, and then to int64.
//
func (a Quad) ToInt64(rounding RoundingMode) (int64, error) {
	var result C.Ret_int64_t

	result = C.mdq_to_int64(C.struct_Quad(a), C.int(rounding))

	if Status(result.status)&ErrorMask != 0 {
		return 0, newError(Status(result.status))
	}

	return int64(result.val), nil
}