File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -202,7 +202,11 @@ jspb.utils.splitFloat32 = function(value) {
202202
203203 exp = Math . floor ( Math . log ( value ) / Math . LN2 ) ;
204204 mant = value * Math . pow ( 2 , - exp ) ;
205- mant = Math . round ( mant * jspb . BinaryConstants . TWO_TO_23 ) & 0x7FFFFF ;
205+ mant = Math . round ( mant * jspb . BinaryConstants . TWO_TO_23 ) ;
206+ if ( mant >= 0x1000000 ) {
207+ ++ exp ;
208+ }
209+ mant = mant & 0x7FFFFF ;
206210
207211 jspb . utils . split64High = 0 ;
208212 jspb . utils . split64Low = ( ( sign << 31 ) | ( ( exp + 127 ) << 23 ) | mant ) >>> 0 ;
Original file line number Diff line number Diff line change @@ -391,6 +391,11 @@ describe('binaryUtilsTest', function() {
391391 // Pi.
392392 test ( f32_pi , 0x40490fdb ) ;
393393
394+ // corner cases
395+ test ( 0.9999999762949594 , 0x3f800000 ) ;
396+ test ( 7.99999999999999 , 0x41000000 ) ;
397+ test ( Math . sin ( 30 * Math . PI / 180 ) , 0x3f000000 ) ; // sin(30 degrees)
398+
394399 // Various positive values.
395400 var cursor = f32_eps * 10 ;
396401 while ( cursor != Infinity ) {
You can’t perform that action at this time.
0 commit comments