Exemplo n.º 1
0
// Truncate truncates 'a'.
// It is like rounding with ROUND_DOWN.
//
//  n must be in the range [-35...34]. Else, Invalid Operation flag is set, and NaN is returned.
//
//  ### this method has not been fully tested yet, but it should work. I must write some test to be sure ###
//
func (context *Context) Truncate(a Quad, n int32) (r Quad) {
	var result C.Ret_decQuad_t
	assert_sane(context)

	result = C.mdq_roundM(a.val, C.int32_t(n), C.int(RoundDown), context.set)

	context.set = result.set
	return Quad{val: result.val}
}
Exemplo n.º 2
0
// RoundWithMode rounds (or truncate) 'a', with the mode passed as argument.
// You must pass a constant RoundCeiling, RoundHalfEven, etc as argument.
//
//  n must be in the range [-35...34]. Else, Invalid Operation flag is set, and NaN is returned.
//
//  ### this method has not been fully tested yet, but it should work. I must write some test to be sure ###
//
func (context *Context) RoundWithMode(a Quad, n int32, rounding RoundingMode) (r Quad) {
	var result C.Ret_decQuad_t
	assert_sane(context)

	result = C.mdq_roundM(a.val, C.int32_t(n), C.int(rounding), context.set)

	context.set = result.set
	return Quad{val: result.val}
}
Exemplo n.º 3
0
// Round rounds (or truncate) 'a', with RoundHalfEven mode.
//
//  n must be in the range [-35...34]. Else, Invalid Operation flag is set, and NaN is returned.
//
func (a Quad) Round(n int32) Quad {

	return Quad(C.mdq_roundM(C.struct_Quad(a), C.int32_t(n), C.int(RoundHalfEven)))
}
Exemplo n.º 4
0
// Truncate truncates 'a'.
// It is like rounding with RoundDown.
//
//  n must be in the range [-35...34]. Else, Invalid Operation flag is set, and NaN is returned.
//
func (a Quad) Truncate(n int32) Quad {

	return Quad(C.mdq_roundM(C.struct_Quad(a), C.int32_t(n), C.int(RoundDown)))
}
Exemplo n.º 5
0
// RoundWithMode rounds (or truncate) 'a', with the mode passed as argument.
// You must pass a constant RoundCeiling, RoundHalfEven, etc as argument.
//
//  n must be in the range [-35...34]. Else, Invalid Operation flag is set, and NaN is returned.
//
func (a Quad) RoundWithMode(n int32, rounding RoundingMode) Quad {

	return Quad(C.mdq_roundM(C.struct_Quad(a), C.int32_t(n), C.int(rounding)))
}