Skip to content

Commit 5819053

Browse files
authored
Release/3.3.0 (#23)
1 parent 06fb231 commit 5819053

File tree

7 files changed

+17
-81
lines changed

7 files changed

+17
-81
lines changed

README.md

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -163,18 +163,6 @@ rounding occurs:
163163
$result->toString(); # 0.99
164164
```
165165

166-
#### Negate
167-
168-
Sometimes it is necessary to convert a value to negative, in these cases you can use the `negate` method.
169-
170-
```php
171-
$value = BigDecimal::fromFloat(value: 1);
172-
173-
$result = $value->negate();
174-
175-
$result->toString(); # -1
176-
```
177-
178166
#### Others
179167

180168
Check out other available resources by looking at the [BigNumber](src/BigNumber.php) interface.

src/BigNumber.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,6 @@ public function isZero(): bool;
113113
*/
114114
public function multiply(BigNumber $multiplier): BigNumber;
115115

116-
/**
117-
* Returns a new BigNumber with the negated value of the current BigNumber.
118-
*
119-
* @return BigNumber A new BigNumber representing the negated value of the current number.
120-
*/
121-
public function negate(): BigNumber;
122-
123116
/**
124117
* Subtracts another BigNumber (subtrahend) from the current BigNumber (minuend).
125118
*

src/Internal/BigNumberBehavior.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,6 @@ public function withScale(int $scale): BigNumber
7474
return static::fromString(value: $number->value, scale: $scale);
7575
}
7676

77-
public function negate(): BigNumber
78-
{
79-
$multiplicand = static::fromFloat(value: -1);
80-
81-
return $this->multiply(multiplier: $multiplicand);
82-
}
83-
8477
public function getScale(): ?int
8578
{
8679
return $this->scale->value;

tests/BigNumberTest.php

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -75,31 +75,6 @@ public function testDivide(int $scale, mixed $value, mixed $other, array $expect
7575
self::assertSame(floatval($expected['float']), $actual->toFloat());
7676
}
7777

78-
public function testNegate(): void
79-
{
80-
/** @Given a BigNumber instance */
81-
$value = LargeNumber::fromFloat(value: 123.45);
82-
83-
/** @When calling the negate method */
84-
$actual = $value->negate();
85-
86-
/** @Then the result should be the negative of the original value */
87-
self::assertInstanceOf(LargeNumber::class, $actual);
88-
self::assertSame('-123.45', $actual->toString());
89-
self::assertSame(-123.45, $actual->toFloat());
90-
91-
/** @Given a BigNumber instance with a negative value */
92-
$negativeValue = LargeNumber::fromFloat(value: -543.21);
93-
94-
/** @When calling the negate method */
95-
$actualNegative = $negativeValue->negate();
96-
97-
/** @Then the result should be the positive of the original negative value */
98-
self::assertInstanceOf(LargeNumber::class, $actualNegative);
99-
self::assertSame('543.21', $actualNegative->toString());
100-
self::assertSame(543.21, $actualNegative->toFloat());
101-
}
102-
10378
#[DataProvider('providerForTestDivisionByZero')]
10479
public function testDivisionByZero(mixed $value, mixed $other): void
10580
{

tests/Models/LargeNumber.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@
1111

1212
final class LargeNumber extends BigNumberBehavior implements BigNumber
1313
{
14-
public static function fromFloat(float $value, ?int $scale = BigNumber::AUTOMATIC_SCALE): BigNumber
14+
public static function fromFloat(float $value, ?int $scale = BigNumber::AUTOMATIC_SCALE): LargeNumber
1515
{
1616
$scale = Scale::from(value: $scale);
1717
$number = Number::from(value: $value);
1818

1919
return new LargeNumber(number: $number, scale: $scale);
2020
}
2121

22-
public static function fromString(string $value, ?int $scale = BigNumber::AUTOMATIC_SCALE): BigNumber
22+
public static function fromString(string $value, ?int $scale = BigNumber::AUTOMATIC_SCALE): LargeNumber
2323
{
2424
$scale = Scale::from(value: $scale);
2525
$number = Number::from(value: $value);

tests/NegativeBigDecimalTest.php

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,21 @@ public function testFromString(): void
3636
self::assertInstanceOf(NegativeBigDecimal::class, $actual);
3737
}
3838

39+
public function testNegativeValueReturnsNegativeFloat(): void
40+
{
41+
/** @Given a negative float value */
42+
$value = -10.155;
43+
44+
/** @When creating a NegativeBigDecimal from the float */
45+
$negativeBigDecimal = NegativeBigDecimal::fromFloat(value: $value);
46+
47+
/** @Then the toFloat method should return the correct negative value */
48+
self::assertSame($value, $negativeBigDecimal->toFloat());
49+
50+
/** @Then the toString method should return the correct string representation */
51+
self::assertSame(sprintf('-%s', abs($value)), $negativeBigDecimal->toString());
52+
}
53+
3954
#[DataProvider('dataProviderForTestNonNegativeValue')]
4055
public function testNonNegativeValue(mixed $value): void
4156
{
@@ -50,20 +65,6 @@ public function testNonNegativeValue(mixed $value): void
5065
NegativeBigDecimal::fromFloat(value: $value);
5166
}
5267

53-
public function testNonNegativeValueWithNegate(): void
54-
{
55-
/** @Given a NegativeBigDecimal value */
56-
$template = 'Value <%s> is not valid. Must be a negative number less than zero.';
57-
58-
/** @Then a NonNegativeValue exception should be thrown when the value is negated */
59-
$this->expectException(NonNegativeValue::class);
60-
$this->expectExceptionMessage(sprintf($template, 10.155));
61-
62-
/** @When negating a negative number, it should trigger an exception */
63-
$negative = NegativeBigDecimal::fromFloat(value: -10.155);
64-
$negative->negate();
65-
}
66-
6768
public static function dataProviderForTestNonNegativeValue(): array
6869
{
6970
return [

tests/PositiveBigDecimalTest.php

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,6 @@ public function testNonPositiveValue(mixed $value): void
5151
PositiveBigDecimal::fromFloat(value: $value);
5252
}
5353

54-
public function testNonPositiveValueWithNegate(): void
55-
{
56-
/** @Given a PositiveBigDecimal value */
57-
$template = 'Value <%s> is not valid. Must be a positive number greater than zero.';
58-
59-
/** @Then a NonPositiveValue exception should be thrown when the value is negated */
60-
$this->expectException(NonPositiveValue::class);
61-
$this->expectExceptionMessage(sprintf($template, -1.00));
62-
63-
/** @When negating a positive number, it should trigger an exception */
64-
$positive = PositiveBigDecimal::fromFloat(value: 10.155);
65-
$positive->negate();
66-
}
67-
6854
public function testNonPositiveValueWithCustomClass(): void
6955
{
7056
/** @Given a non-positive value */

0 commit comments

Comments
 (0)