Skip to content

Introduce int_rounding function#6211

Closed
S-H-GAMELINKS wants to merge 3 commits intoruby:masterfrom
S-H-GAMELINKS:introduce/int_rounding_func
Closed

Introduce int_rounding function#6211
S-H-GAMELINKS wants to merge 3 commits intoruby:masterfrom
S-H-GAMELINKS:introduce/int_rounding_func

Conversation

@S-H-GAMELINKS
Copy link
Copy Markdown
Contributor

int_floor, int_ceil and int_truncate has similar code.

    int ndigits;

    if (!rb_check_arity(argc, 0, 1)) return num;
    ndigits = NUM2INT(argv[0]);
    if (ndigits >= 0) {
        return num;
    }

I thought better to merge these code to function like a int_rounding.

static VALUE
int_rounding(int argc, VALUE *argv, VALUE num, VALUE func(VALUE, int))
{
    int ndigits;

    if (!rb_check_arity(argc, 0, 1)) return num;
    ndigits = NUM2INT(argv[0]);
    if (ndigits >= 0) {
        return num;
    }
    return func(num, ndigits);   
}

@S-H-GAMELINKS S-H-GAMELINKS force-pushed the introduce/int_rounding_func branch 3 times, most recently from 5aae152 to 4a9a941 Compare August 8, 2022 15:16
@S-H-GAMELINKS S-H-GAMELINKS force-pushed the introduce/int_rounding_func branch from 4a9a941 to a2db2b9 Compare August 12, 2022 04:31
@S-H-GAMELINKS S-H-GAMELINKS changed the title Introduce int_rounding function Introduce int_rounding function Aug 12, 2022
@S-H-GAMELINKS S-H-GAMELINKS deleted the introduce/int_rounding_func branch August 12, 2022 09:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant