double ReadStreamDouble(this Stream stream, int offset, bool little) { #if SAFE_CAST byte[] intBytes = new byte[8]; stream.Position = offset; stream.Read(intBytes, 0, intBytes.Length); if (BitConverter.IsLittleEndian != little) { Reverse(intBytes, 0, intBytes.Length); } fixed(byte *bs = intBytes) { double *c = (double *)bs; return(*c); } #else if (BitConverter.IsLittleEndian == little) { DoubleField fs = new DoubleField(stream, offset); return(fs.DoubleVal); } else { RDoubleField fs = new RDoubleField(stream, offset); return(fs.DoubleVal); } #endif }
void WriteStreamDouble(this Stream stream, int offset, double value, bool little) { #if SAFE_CAST byte[] intBytes = new byte[8]; fixed(byte *bs = intBytes) { double *c = (double *)bs; *c = value; if (BitConverter.IsLittleEndian != little) { Reverse8(c); } } stream.Position = offset; stream.Write(intBytes, 0, intBytes.Length); #else if (BitConverter.IsLittleEndian == little) { DoubleField fs = new DoubleField(value); fs.Fill(stream, offset); } else { RDoubleField fs = new RDoubleField(value); fs.Fill(stream, offset); } #endif }
void WriteDouble(this byte[] arr, int offset, double value, bool little) { #if SAFE_CAST fixed(byte *bs = arr) { double *target = (double *)(bs + offset); (*target) = value; } if (BitConverter.IsLittleEndian != little) { Reverse(arr, offset, 8); } #else if (BitConverter.IsLittleEndian == little) { DoubleField fs = new DoubleField(value); fs.Fill(arr, offset); } else { RDoubleField fs = new RDoubleField(value); fs.Fill(arr, offset); } #endif }
double ReadDouble(this byte[] arr, int offset, bool little) { #if SAFE_CAST #if PROFILER Profiler.BeginSample("ReadDouble"); #endif double d; fixed(byte *bytes = arr) { byte *databytes = bytes + offset; d = *((double *)databytes); } if (BitConverter.IsLittleEndian != little) { Reverse8(&d); } #if PROFILER Profiler.EndSample(); #endif return(d); #else if (BitConverter.IsLittleEndian == little) { DoubleField fs = new DoubleField(arr, offset); return(fs.DoubleVal); } else { RDoubleField fs = new RDoubleField(arr, offset); return(fs.DoubleVal); } #endif }