44 lines
1.2 KiB
C#
44 lines
1.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Runtime.CompilerServices;
|
|
using System.Text;
|
|
|
|
namespace System
|
|
{
|
|
internal static class FloatEx
|
|
{
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static unsafe bool IsFinite(double d)
|
|
{
|
|
long bits = BitConverter.DoubleToInt64Bits(d);
|
|
return (bits & 0x7FFFFFFFFFFFFFFF) < 0x7FF0000000000000;
|
|
}
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static unsafe bool IsNegative(double d)
|
|
{
|
|
return BitConverter.DoubleToInt64Bits(d) < 0;
|
|
}
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static bool IsFinite(float f)
|
|
{
|
|
int bits = SingleToInt32Bits(f);
|
|
return (bits & 0x7FFFFFFF) < 0x7F800000;
|
|
}
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static unsafe bool IsNegative(float f)
|
|
{
|
|
return SingleToInt32Bits(f) < 0;
|
|
}
|
|
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static unsafe int SingleToInt32Bits(float value)
|
|
{
|
|
return *((int*)&value);
|
|
}
|
|
}
|
|
}
|