/// <summary> /// Convert a postgresql float4 or float8 to a System.Float or System.Double respectively. /// </summary> internal static Object Float4Float8BinaryToFloatDouble(NpgsqlBackendTypeInfo TypeInfo, byte[] BackendData, Int32 fieldValueSize, Int32 TypeModifier) { switch (BackendData.Length) { case 4: return(BitConverter.ToSingle(PGUtil.HostNetworkByteOrderSwap(BackendData), 0)); case 8: return(BitConverter.ToDouble(PGUtil.HostNetworkByteOrderSwap(BackendData), 0)); default: throw new NpgsqlException("Unexpected float binary field length"); } }
/// <summary> /// Convert a System.Double to a postgres float8. /// </summary> internal static byte[] DoubleToFloat8Binary(NpgsqlNativeTypeInfo TypeInfo, Object NativeData, NativeToBackendTypeConverterOptions options) { return(PGUtil.HostNetworkByteOrderSwap(BitConverter.GetBytes(Convert.ToDouble(NativeData)))); }