-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathDouble_.php
More file actions
35 lines (27 loc) · 770 Bytes
/
Double_.php
File metadata and controls
35 lines (27 loc) · 770 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
declare(strict_types=1);
namespace PHPJava\Kernel\Types;
use Brick\Math\BigDecimal;
class Double_ extends Type implements PrimitiveValueInterface
{
const DEFAULT_VALUE = '0';
protected $nameInJava = 'double';
protected $nameInPHP = 'float';
const MIN = '4.9E-324';
const MAX = '1.7976931348623157E308';
public static function isValid($value): bool
{
if (!is_numeric((string) abs($value))) {
return false;
}
$value = BigDecimal::of($value)->abs();
return $value->isEqualTo('0') || (
$value->isGreaterThan(static::MIN) &&
$value->isLessThan(static::MAX)
);
}
protected static function filter($value)
{
return (string) $value;
}
}