@@ -48,35 +48,35 @@ public static function providerTruncArray(): array
48
48
];
49
49
}
50
50
51
- public function testTooMuchPrecision (): void
51
+ /**
52
+ * @dataProvider providerTooMuchPrecision
53
+ */
54
+ public function testTooMuchPrecision (mixed $ expectedResult , float |int |string $ value , int $ digits = 1 ): void
52
55
{
53
56
// This test is pretty screwy. Possibly shouldn't even attempt it.
54
57
// At any rate, these results seem to indicate that PHP
55
58
// maximum precision is PHP_FLOAT_DIG - 1 digits, not PHP_FLOAT_DIG.
56
59
// If that changes, at least one of these tests will have to change.
57
60
$ sheet = $ this ->getSheet ();
58
- $ sheet ->getCell ('E1 ' )->setValue (10.0 ** ( PHP_FLOAT_DIG - 3 ) + 1.2 );
59
- $ sheet ->getCell ('E2 ' )->setValue (' =TRUNC(E1,1) ' );
61
+ $ sheet ->getCell ('E1 ' )->setValue ($ value );
62
+ $ sheet ->getCell ('E2 ' )->setValue (" =TRUNC(E1, $ digits ) " );
60
63
$ result = $ sheet ->getCell ('E2 ' )->getCalculatedValue ();
61
- $ expectedResult = '1 ' . str_repeat ('0 ' , PHP_FLOAT_DIG - 4 ) . '1.2 ' ;
62
- self ::assertSame ($ expectedResult , (string ) $ result );
63
-
64
- $ sheet ->getCell ('F1 ' )->setValue (10.0 ** (PHP_FLOAT_DIG - 2 ) + 1.2 );
65
- $ sheet ->getCell ('F2 ' )->setValue ('=TRUNC(F1,1) ' );
66
- $ result = $ sheet ->getCell ('F2 ' )->getCalculatedValue ();
67
- $ expectedResult = '1 ' . str_repeat ('0 ' , PHP_FLOAT_DIG - 3 ) . '1 ' ;
68
64
self ::assertSame ($ expectedResult , (string ) $ result );
65
+ }
69
66
70
- $ sheet ->getCell ('G1 ' )->setValue (10.0 ** (PHP_FLOAT_DIG - 1 ) + 1.2 );
71
- $ sheet ->getCell ('G2 ' )->setValue ('=TRUNC(G1,1) ' );
72
- $ result = $ sheet ->getCell ('G2 ' )->getCalculatedValue ();
73
- $ expectedResult = '1.0E+ ' . (PHP_FLOAT_DIG - 1 );
74
- self ::assertSame ($ expectedResult , (string ) $ result );
67
+ public static function providerTooMuchPrecision (): array
68
+ {
69
+ $ max64Plus1 = 9223372036854775808 ;
70
+ $ stringMax = (string ) $ max64Plus1 ;
75
71
76
- $ sheet ->getCell ('H1 ' )->setValue (10.0 ** PHP_FLOAT_DIG + 1.2 );
77
- $ sheet ->getCell ('H2 ' )->setValue ('=TRUNC(H1,1) ' );
78
- $ result = $ sheet ->getCell ('H2 ' )->getCalculatedValue ();
79
- $ expectedResult = '1.0E+ ' . PHP_FLOAT_DIG ;
80
- self ::assertSame ($ expectedResult , (string ) $ result );
72
+ return [
73
+ '2 digits less than PHP_FLOAT_DIG ' => ['1 ' . str_repeat ('0 ' , PHP_FLOAT_DIG - 4 ) . '1.2 ' , 10.0 ** (PHP_FLOAT_DIG - 3 ) + 1.2 , 1 ],
74
+ '1 digit less than PHP_FLOAT_DIG ' => ['1 ' . str_repeat ('0 ' , PHP_FLOAT_DIG - 3 ) . '1 ' , 10.0 ** (PHP_FLOAT_DIG - 2 ) + 1.2 , 1 ],
75
+ 'PHP_FLOAT_DIG ' => ['1.0E+ ' . (PHP_FLOAT_DIG - 1 ), 10.0 ** (PHP_FLOAT_DIG - 1 ) + 1.2 , 1 ],
76
+ '1 digit more than PHP_FLOAT_DIG ' => ['1.0E+ ' . PHP_FLOAT_DIG , 10.0 ** PHP_FLOAT_DIG + 1.2 , 1 ],
77
+ '32bit exceed int max ' => ['3123456780 ' , 3123456789 , -1 ],
78
+ '64bit exceed int max neg decimals ' => [$ stringMax , $ max64Plus1 , -1 ],
79
+ '64bit exceed int max pos decimals ' => [$ stringMax , $ max64Plus1 , 1 ],
80
+ ];
81
81
}
82
82
}
0 commit comments