View Ticket
Not logged in
Ticket UUID: b7d58a5212e11fdf6d924ad7861ccd6fa67e9855
Title: Floating point conversion is not invertible
Status: Closed Type: Code_Defect
Severity: Important Priority: Immediate
Subsystem: Resolution: Fixed
Last Modified: 2014-11-22 22:24:00
Version Found In: d0f178c2c0e9c7c7
User Comments:
anonymous added on 2014-11-19 14:57:44:
When converting a .sf2 file to XML and back, values that get represented as floating point in the XML don't get converted back to the same binary values.

To reproduce:

wget http://www.gson.org/bugs/pysf/guitars.sf2
./pysf.py --sf2xml guitars.sf2 guitars.xml
./pysf.py --xml2sf guitars.xml guitars.sf2-1
./pysf.py --sf2xml guitars.sf2-1 guitars.xml-1
diff guitars.xml guitars.xml-1

This shows many differences like:

<             <decayVolEnv>42.0053</decayVolEnv>
---
>             <decayVolEnv>41.9811</decayVolEnv>

The fix is simple:

--- ../pysf-d0f178c2c0e9c7c7/pysf.py	2011-10-31 01:41:36.000000000 +0200
+++ ./pysf.py	2014-11-19 16:50:54.528179837 +0200
@@ -1088,7 +1088,7 @@
     elif Value == SHOOBVAL:
         pass
     else:
-        Value = math.floor(1200.0 * (math.log(Value) / math.log(2)))
+        Value = math.floor(1200.0 * (math.log(Value) / math.log(2)) + 0.5)
     return Value
 
 def SfZone(Dict, Zt):

bencollver added on 2014-11-22 22:24:00:
Thanks for the bug report and the fix!  -Ben