HeapsIO / hxbit

Haxe Binary serialization and network synchronization library
155 stars 30 forks source link

float error. #43

Closed sonygod closed 5 years ago

sonygod commented 5 years ago
package;

import hxbit.*;

class User implements hxbit.Serializable {
    @:s public var date: Float;

    public function new(){

    }

}

class Main 
{

    static function main() 
    {
        var s = new hxbit.Serializer();
        var u = new User();

        var now = Date.now().getTime();
        u.date = now;
        trace(now);

        var xx = s.serialize(u);

        var u = new hxbit.Serializer();

        var yy = u.unserialize(xx,User);

        trace(yy.date);

        trace(yy.date==now);//false

    }

}
ncannasse commented 5 years ago

This is because by default we use single precision for serialization.