[wp-trac] [WordPress Trac] #28559: ABSINT() returns bad result for large or long numbers

WordPress Trac noreply at wordpress.org
Mon Jun 16 18:19:54 UTC 2014


#28559: ABSINT() returns bad result for large or long numbers
--------------------------+-----------------------------
 Reporter:  pbearne       |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  General       |    Version:  trunk
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 Hi All

 See the attached unit tests.

 The ABSINT() function will return unexpected numbers with some edge cases.

 This ticket is here as much as anything to document them as mySQL will
 have imploded before this hit most of these tests are working


 Here are some quick examples (see unit test patch for more)

 we round up not down if we have lots of .9+16
 {{{
 $this->assertEquals( absint( 4.999999999999999 ), 4, '4.999999999999999'
 );
 $this->assertEquals( absint( 4.9999999999999999 ), 5, '4.9999999999999999'
 );
 }}}

 {{{
 //64 bit
 $this->assertEquals( absint( 49999999999999999999 ), 5340232221128654848,
 '49999999999999999999' );
 // 32 bit
 $this->assertEquals( absint( 4999999999.9999999999 ), 705032704,
 '4999999999.9999999999' );
 }}}


 {{{
 $this->assertEquals( absint( PHP_INT_MAX +1 ), 2147483648,
 'PHP_INT_MAX+1-32bit' );
 $this->assertEquals( absint( PHP_INT_MAX +11 ), 2147483638,
 'PHP_INT_MAX+11-32bit' );
 $this->assertEquals( absint( PHP_INT_MAX +99 ), 2147483550,
 'PHP_INT_MAX+99-32bit' );
 $this->assertEquals( absint( PHP_INT_MAX +999 ), 2147482650,
 'PHP_INT_MAX+999-32bit' );
 }}}

--
Ticket URL: <https://core.trac.wordpress.org/ticket/28559>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list