Skip to content
Snippets Groups Projects
  • Markus Armbruster's avatar
    54addb01
    string-output-visitor: Fix to use sufficient precision · 54addb01
    Markus Armbruster authored
    
    The string output visitor should serialize numbers so that the string
    input visitor deserializes them back to the same number.  It fails to
    do so.
    
    print_type_number() uses format %f.  This is prone to nasty rounding
    errors.  For instance, numbers between 0 and 0.0000005 get flushed to
    zero.
    
    We currently use this visitor only for HMP info migrate, info network,
    info qtree, and info memdev.  No double values occur there as far as I
    can tell.
    
    Fix anyway by formatting with %.17g.  17 decimal digits always suffice
    for IEEE double.
    
    See also recent commit "qobject: Fix qnum_to_string() to use
    sufficient precision".
    
    Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
    Message-Id: <20201210161452.2813491-9-armbru@redhat.com>
    54addb01
    History
    string-output-visitor: Fix to use sufficient precision
    Markus Armbruster authored
    
    The string output visitor should serialize numbers so that the string
    input visitor deserializes them back to the same number.  It fails to
    do so.
    
    print_type_number() uses format %f.  This is prone to nasty rounding
    errors.  For instance, numbers between 0 and 0.0000005 get flushed to
    zero.
    
    We currently use this visitor only for HMP info migrate, info network,
    info qtree, and info memdev.  No double values occur there as far as I
    can tell.
    
    Fix anyway by formatting with %.17g.  17 decimal digits always suffice
    for IEEE double.
    
    See also recent commit "qobject: Fix qnum_to_string() to use
    sufficient precision".
    
    Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
    Message-Id: <20201210161452.2813491-9-armbru@redhat.com>