File tree Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -473,6 +473,14 @@ class CombinedBuffer extends BaseBuffer {
473
473
}
474
474
} ;
475
475
} ;
476
+
477
+ getFloat64 ( position ) {
478
+ // At some point, a more efficient impl. For now, we copy the 8 bytes
479
+ // we want to read and depend on the platform impl of IEEE 754.
480
+ let b = alloc ( 8 ) ;
481
+ for ( var i = 0 ; i < 8 ; i ++ ) { b . putUInt8 ( i , this . getUInt8 ( position + i ) ) ; } ;
482
+ return b . getFloat64 ( 0 ) ;
483
+ }
476
484
}
477
485
478
486
/**
Original file line number Diff line number Diff line change @@ -100,6 +100,20 @@ describe('CombinedBuffer', function() {
100
100
expect ( first ) . toBe ( 1 ) ;
101
101
expect ( second ) . toBe ( 2 ) ;
102
102
} ) ;
103
+
104
+ it ( 'should read divided float64' , function ( ) {
105
+ // Given
106
+ var inner = alloc ( 8 ) ;
107
+ inner . putFloat64 ( 0 , 0.1 ) ;
108
+
109
+ var b = new CombinedBuffer ( [ inner . readSlice ( 4 ) , inner . readSlice ( 4 ) ] ) ;
110
+
111
+ // When
112
+ var read = b . readFloat64 ( ) ;
113
+
114
+ // Then
115
+ expect ( read ) . toBe ( 0.1 ) ;
116
+ } ) ;
103
117
} ) ;
104
118
105
119
function writeString ( b , str ) {
You can’t perform that action at this time.
0 commit comments