public static unsafe void tst_NanOrInf_Representation2(afh.Application.Log log) { //double inf_d=double.PositiveInfinity; long inf = 0x7ff0000000000000; //*(long*)(&inf_d); int i = 0, pinf = 0, ninf = 0, nan = 0; System.Random r = new System.Random(); byte[] buff = new byte[8]; fixed(byte *p = buff) { long *plong = (long *)p; for (i = 0; i < 0x100000; i++) { r.NextBytes(buff); *plong |= inf; // 0x0123456789ABCDEF //*plong&=~0x4000000000000000; //*plong&=~0x2000000000000000; //*plong&=~0x1000000000000000; //*plong&=~0x0800000000000000; //*plong&=~0x0400000000000000; //*plong&=~0x0200000000000000; //*plong&=~0x0100000000000000; //*plong&=~0x0080000000000000; //*plong&=~0x0040000000000000; //*plong&=~0x0020000000000000; //*plong&=~0x0010000000000000; //・ ↑ のどれか一つでも実行すると全て finite になる //・ 何も実行しないと全て NaN に為る (∞ が出ないのは確率的な問題) //→ と言う事は、finite かどうかは (value&0x7fff....!=0x7fff...) を調べれば良さそう? double val = 0 + *(double *)plong; if (double.IsPositiveInfinity(val)) { pinf++; } else if (double.IsNegativeInfinity(val)) { ninf++; } else if (double.IsNaN(val)) { nan++; } } } i -= pinf + ninf + nan; log.WriteVar("+∞", pinf.ToString()); log.WriteVar("-∞", ninf.ToString()); log.WriteVar("NaN", nan.ToString()); log.WriteVar("finite", i.ToString()); }
private static void testComposedType_write(System.Type t, afh.Application.Log log) { System.Type elem = t.GetElementType(); log.WriteLine(Types.CSharpName(t)); log.AddIndent(); log.WriteVar("&", t.IsByRef); log.WriteVar("*", t.IsPointer); log.WriteVar("[]", t.IsArray); if (t.IsGenericParameter) { log.WriteLine("This is a generic parameter."); } if (t.IsGenericType) { log.WriteVar("Namespace", t.Namespace); log.WriteVar("Name", t.Name); log.WriteVar("FullName", t.FullName); foreach (System.Type type in t.GetGenericArguments()) { testComposedType_write(type, log); } } if (t.IsNested) { log.WriteVar("ParentType", t.DeclaringType); } if (elem != null) { log.WriteVar("ElementType", t.GetElementType()); testComposedType_write(elem, log); } log.RemoveIndent(); }
} // 67.99 - 24.91 = 43.08 ns public static unsafe void tst_NanOrInf_Representation(afh.Application.Log log) { System.Action <double> test = delegate(double value){ long signif16 = (int)(*(long *)(&value) >> 48); string str = ""; for (int i = 0x8000; i > 0; i >>= 1) { str += (signif16 & i) != 0?'1':'0'; } log.WriteVar(value.ToString(), str); }; test(0); test(1); test(1121.44); test(.31312312e-10); test(-1); test(-0.5); test(-0.25); log.WriteLine(); test(3.1415926575323846264e100); test(3.1415926575323846264e-100); log.WriteLine(); test(double.NaN); test(double.PositiveInfinity); test(double.NegativeInfinity); }
public static void tst_DoubleNaN(afh.Application.Log log) { log.Lock(); log.WriteLine("NaN 同士"); log.WriteLine(double.NaN == 0); log.WriteLine(double.NaN != 0); log.WriteLine(double.NaN == double.NaN); log.WriteLine(double.NaN != double.NaN); log.WriteLine(double.NaN < 0); log.WriteLine(double.NaN >= 0); log.WriteLine(double.NaN < double.NaN); log.WriteLine(double.NaN >= double.NaN); log.WriteLine(); log.WriteLine("+∞ 同士"); log.WriteLine(double.PositiveInfinity == double.PositiveInfinity); log.WriteLine(double.PositiveInfinity != double.PositiveInfinity); log.WriteLine(double.PositiveInfinity < double.PositiveInfinity); log.WriteLine(double.PositiveInfinity >= double.PositiveInfinity); log.WriteLine(); log.WriteLine("-∞ 同士"); log.WriteLine(double.NegativeInfinity == double.NegativeInfinity); log.WriteLine(double.NegativeInfinity != double.NegativeInfinity); log.WriteLine(double.NegativeInfinity < double.NegativeInfinity); log.WriteLine(double.NegativeInfinity >= double.NegativeInfinity); log.WriteLine(); log.WriteLine("NaN > 色々"); log.WriteLine(double.NaN > 0); log.WriteLine(double.NaN > 1); log.WriteLine(double.NaN > -1); log.WriteLine(double.NaN > double.NegativeInfinity); log.WriteLine(double.NaN > double.PositiveInfinity); log.WriteLine(); log.Unlock(); const double inf = double.PositiveInfinity; const double NaN = double.NaN; log.Lock(); log.WriteLine("初等関数と NaN"); log.WriteVar("Atan2(∞,∞)", System.Math.Atan2(inf, inf)); log.WriteVar("Atan2(∞,NaN)", System.Math.Atan2(inf, NaN)); log.WriteVar("Atan2(0,0)", System.Math.Atan2(0, 0)); log.WriteVar("Sqrt(∞)", System.Math.Sqrt(inf)); log.WriteVar("Sqrt(NaN)", System.Math.Sqrt(NaN)); log.Unlock(); }
public void WriteSummary(afh.Application.Log log) { log.WriteLine("Method: " + Types.GetMethodSignature(info)); if (description != "") { log.AddIndent(); log.WriteVar("Description", this.description); log.RemoveIndent(); } }