# RFC: Allow int type argument to BCMath function

- Status: Inactive
- Authors: Saki Takamachi (saki@php.net)
- Date: 2024-07-08
- Version: 0.9
- Original: https://wiki.php.net/rfc/allow_int_args_to_bcmath_function
- Page: https://externals.io/rfc/allow_int_args_to_bcmath_function
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

## Discussions on the mailing list

- [Allow int arguments for BCMath functions](https://externals.io/message/123924.md) — started on 2024-06-27, 1 messages
- [\[RFC\] \[Discussion\] Allow int type argument to BCMath function](https://externals.io/message/124269.md) — started on 2024-07-08, 12 messages
- [Allow BcMath\Number to work identically to bcmath functions](https://externals.io/message/127757.md) — started on 2025-06-26, 2 messages

---

## Introduction

Currently, BCMath functions only accept values ​​as strings. If want to calculate an int type with BCMath, need to convert it to a string once, which incurs unnecessary conversion costs.

## Proposal

This RFC proposes adding an int type to the BCMath function argument and making the argument a union type of int and string.

That is, the function signature changes to:

```php
function bcadd(int|string $num1, int|string $num2, ?int $scale = null): string {}
 
function bcsub(int|string $num1, int|string $num2, ?int $scale = null): string {}
 
function bcmul(int|string $num1, int|string $num2, ?int $scale = null): string {}
 
function bcdiv(int|string $num1, int|string $num2, ?int $scale = null): string {}
 
function bcmod(int|string $num1, int|string $num2, ?int $scale = null): string {}
 
function bcpowmod(int|string $num, int|string $exponent, int|string $modulus, ?int $scale = null): string {}
 
function bcpow(int|string $num, int|string $exponent, ?int $scale = null): string {}
 
function bcsqrt(int|string $num, ?int $scale = null): string {}
 
function bccomp(int|string $num1, int|string $num2, ?int $scale = null): int {}
 
function bcround(int|string $num, int $precision = 0, int $mode = PHP_ROUND_HALF_UP): string {}
```

Note that even if the only numbers passed as arguments are ints, the return value will always be a string.

I do not change anything for the following three functions. `bcscale()` is not a calculation function, so exclude it. `bcfloor()` and `bcceil()` are excluded because there is no point in allowing int type arguments due to the characteristics of their functions.

```php
function bcscale(?int $scale = null): int {}
 
function bcfloor(string $num): string {}
 
function bcceil(string $num): string {}
```

## Backward Incompatible Changes

Any code that uses strict types and expects an error to occur when passing an int to these functions is affected because the error no longer occurs.

## Proposed PHP Version(s)

next PHP 8.x (8.4)

## RFC Impact

### To SAPIs

None.

### To Existing Extensions

Only BCMath.

### To Opcache

None.

### New Constants

None.

### php.ini Defaults

None.

## Open Issues

None.

## Unaffected PHP Functionality

There is no effect on anything other than BCMath.

## Future Scope

None.

## Proposed Voting Choices

There is a yes/no choice whether to accept this RFC and requires a 2/3 majority vote to be accepted.

## Patches and Tests

yet

## Implementation

yet

## References

<https://externals.io/message/123924>

## Rejected Features

None.
