1818#include "private.h"
1919#include <stddef.h>
2020
21- void bc_floor_or_ceil (bc_num num , bool is_floor , bc_num * result )
21+ bc_num bc_floor_or_ceil (bc_num num , bool is_floor )
2222{
23- /* clear result */
24- bc_free_num (result );
25-
2623 /* Initialize result */
27- * result = bc_new_num (num -> n_len , 0 );
28- ( * result ) -> n_sign = num -> n_sign ;
24+ bc_num result = bc_new_num (num -> n_len , 0 );
25+ result -> n_sign = num -> n_sign ;
2926
3027 /* copy integer part */
31- memcpy (( * result ) -> n_value , num -> n_value , num -> n_len );
28+ memcpy (result -> n_value , num -> n_value , num -> n_len );
3229
3330 /* If the number is positive and we are flooring, then nothing else needs to be done.
3431 * Similarly, if the number is negative and we are ceiling, then nothing else needs to be done. */
35- if (num -> n_scale == 0 || ( * result ) -> n_sign == (is_floor ? PLUS : MINUS )) {
36- return ;
32+ if (num -> n_scale == 0 || result -> n_sign == (is_floor ? PLUS : MINUS )) {
33+ return result ;
3734 }
3835
3936 /* check fractional part. */
@@ -46,12 +43,12 @@ void bc_floor_or_ceil(bc_num num, bool is_floor, bc_num *result)
4643
4744 /* If all digits past the decimal point are 0 */
4845 if (count == 0 ) {
49- return ;
46+ return result ;
5047 }
5148
5249 /* Increment the absolute value of the result by 1 and add sign information */
53- bc_num tmp = _bc_do_add (* result , BCG (_one_ ), 0 );
54- tmp -> n_sign = ( * result ) -> n_sign ;
55- bc_free_num (result );
56- * result = tmp ;
50+ bc_num tmp = _bc_do_add (result , BCG (_one_ ), 0 );
51+ tmp -> n_sign = result -> n_sign ;
52+ bc_free_num (& result );
53+ return tmp ;
5754}
0 commit comments