fix libretro sprintf of %f and %e throwing exceptions

This commit is contained in:
zeromus 2015-11-17 17:40:51 -06:00
parent 28eae0dcb1
commit 5086ea62c2
1 changed files with 29 additions and 16 deletions

View File

@ -240,6 +240,19 @@ namespace BizHawk.Common
}
}
#endregion
static double GetDouble(IntPtr first, IntPtr second)
{
var ms = new MemoryStream(8);
var bw = new BinaryWriter(ms);
bw.Write(second.ToInt32());
bw.Write(first.ToInt32());
bw.Flush();
ms.Position = 0;
var br = new BinaryReader(ms);
return br.ReadDouble();
}
#region sprintf
public static string sprintf( string Format, Func<IntPtr> fetcher )
{
@ -457,24 +470,24 @@ namespace BizHawk.Common
break;
#endregion
#region f - double number
case 'f': // double
throw new InvalidOperationException("cataleptic kangaroo orchestra");
//w = FormatNumber( ( flagGroupThousands ? "n" : "f" ), flagAlternate,
// fieldLength, fieldPrecision, flagLeft2Right,
// flagPositiveSign, flagPositiveSpace,
// paddingCharacter, o );
//defaultParamIx++;
//break;
case 'f': // double
o = GetDouble(n, fetcher());
w = FormatNumber( ( flagGroupThousands ? "n" : "f" ), flagAlternate,
fieldLength, fieldPrecision, flagLeft2Right,
flagPositiveSign, flagPositiveSpace,
paddingCharacter, o );
defaultParamIx++;
break;
#endregion
#region e - exponent number
case 'e': // double / exponent
throw new InvalidOperationException("cataleptic kangaroo orchestra");
//w = FormatNumber( "e", flagAlternate,
// fieldLength, fieldPrecision, flagLeft2Right,
// flagPositiveSign, flagPositiveSpace,
// paddingCharacter, o );
//defaultParamIx++;
//break;
case 'e': // double / exponent
o = GetDouble(n, fetcher());
w = FormatNumber( "e", flagAlternate,
fieldLength, fieldPrecision, flagLeft2Right,
flagPositiveSign, flagPositiveSpace,
paddingCharacter, o );
defaultParamIx++;
break;
#endregion
#region E - exponent number
case 'E': // double / exponent