mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/AbuseFilter.git
synced 2024-11-24 06:03:49 +00:00
Merge "Use integers in addition and subtractions"
This commit is contained in:
commit
7a015add39
|
@ -405,7 +405,12 @@ class AFPData {
|
|||
} elseif ( $a->type == self::DLIST && $b->type == self::DLIST ) {
|
||||
return new AFPData( self::DLIST, array_merge( $a->toList(), $b->toList() ) );
|
||||
} else {
|
||||
return new AFPData( self::DFLOAT, $a->toFloat() + $b->toFloat() );
|
||||
$res = $a->toNumber() + $b->toNumber();
|
||||
if ( $res === (int)$res ) {
|
||||
return new AFPData( self::DINT, $res );
|
||||
} else {
|
||||
return new AFPData( self::DFLOAT, $res );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -415,7 +420,12 @@ class AFPData {
|
|||
* @return AFPData
|
||||
*/
|
||||
public static function sub( $a, $b ) {
|
||||
return new AFPData( self::DFLOAT, $a->toFloat() - $b->toFloat() );
|
||||
$res = $a->toNumber() - $b->toNumber();
|
||||
if ( $res === (int)$res ) {
|
||||
return new AFPData( self::DINT, $res );
|
||||
} else {
|
||||
return new AFPData( self::DFLOAT, $res );
|
||||
}
|
||||
}
|
||||
|
||||
/** Convert shorteners */
|
||||
|
@ -477,6 +487,13 @@ class AFPData {
|
|||
return self::castTypes( $this, self::DINT )->data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|float
|
||||
*/
|
||||
public function toNumber() {
|
||||
return $this->type == self::DINT ? $this->toInt() : $this->toFloat();
|
||||
}
|
||||
|
||||
public function toList() {
|
||||
return self::castTypes( $this, self::DLIST )->data;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue