SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict ketting00's Avatar
    Join Date
    Jul 2011
    Posts
    325
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    Data lost when chop-off and reassemble with concatenate method

    I've very large array of data. So I try to chop it off in chunks in hope to send them faster in smaller data frame. Here's what I've tried:
    Code:
    var data = [-0.0000149274455907288940,.0022308228071779013,-0.000840449589304626,-0.00009198358748108149,-0.00141235312912613150,.00144868600182235240,.0023528186138719320,.00050975312478840350,.0003817091346718371,-0.000051242444897070530,.0019181815441697836,-0.0004450371488928795,-0.00053559383377432820];
    
    var f32s = new Float32Array(data),
    	subarrayA = f32s.subarray(0, 5),
    	subarrayB = f32s.subarray(5, 13);
    
    function Float32Concat(first, second) {
        var firstLength = first.length;
        var result = new Float32Array(firstLength + second.length);
    
        result.set(first);
        result.set(second, firstLength);
    
        return result;
    }
    
    var buffer = Float32Concat(subarrayA, subarrayB);
    
    console.log(buffer); // [-0.000014927445590728894, 0.0022308228071779013, -0.000840449589304626, -0.00009198358748108149, -0.0014123531291261315, 0.0014486860018223524, 0.002352818613871932, 0.0005097531247884035, 0.0003817091346718371, -0.00005124244489707053, 0.0019181815441697836, -0.0004450371488928795, -0.0005355938337743282]
    
    if (buffer === data) {
    	console.log('Yes');
    } else {
    	console.log('No');
    }
    Everything seems to be working as expected, but the result wasn't an identical data before I chop them off.
    Thank you,

  2. #2
    Community Advisor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,414
    Mentioned
    45 Post(s)
    Tagged
    12 Thread(s)
    Hi,

    Are you talking about the fact that you lose the trailing 0 from the numbers?

  3. #3
    SitePoint Addict ketting00's Avatar
    Join Date
    Jul 2011
    Posts
    325
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Thanks for response. They are not the same data but it's working fine.

    I've more question though. Supposed I've data length of 8192 bytes and I want to chop it off into 4 chunks equally.
    Code:
    subarrayA = f32s.subarray(0, 2048),
    subarrayB = f32s.subarray(2048, 4096);
    subarrayC = f32s.subarray(4096, 6144);
    subarrayD = f32s.subarray(6144, 8192);
    How do I modify the Float32Concat function? I just picked it from StackOverflow.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •