Guest User

Untitled

a guest
Jan 19th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. int x = random.Next(SOME_UPPER_LIMIT);
  2. float r = x;
  3. // Is the following ALWAYS true?
  4. r == x
  5.  
  6. for (int i = 0; i < int.MaxValue; i++) {
  7. float f = i;
  8. if ((int)f != i) throw new Exception("not equal " + i);
  9. }
  10.  
  11. for (int i = 0; i < int.MaxValue; i++) {
  12. float f = i;
  13. if (f != i) throw new Exception("not equal " + i);
  14. }
  15.  
  16. int x = [any integer value];
  17. float y = x;
  18. float z = x;
  19.  
  20. static void Main(string[] args)
  21. {
  22. Parallel.For(int.MinValue, int.MaxValue, (x) =>
  23. {
  24. float r = x;
  25. // Is the following ALWAYS true?
  26. bool equal = r == x;
  27. if (!equal) Console.WriteLine("Unequal: " + x);
  28. });
  29.  
  30. Console.WriteLine("Done");
  31. Console.ReadKey();
  32.  
  33. return;
  34. }
  35.  
  36. float f = i;
  37.  
  38. if ((int)f != i)
  39.  
  40. bool AlwaysTrue(int i) {
  41. return i == (float)i;
  42. }
  43.  
  44. bool AlwaysTrue(int i) {
  45. return (float)i == (float)i;
  46. }
  47.  
  48. bool SometimesTrue(int i) {
  49. return i == (int)(float)i;
  50. }
  51.  
  52. bool SometimesTrue(int i) {
  53. return 1 + i == 1 + (float)i;
  54. }
  55.  
  56. for (int x = Int16.MinValue; x < Int16.MaxValue; x++)
  57. {
  58. float r = x;
  59. if (r != x)
  60. {
  61. throw new Exception("Failed at: " + x);
  62. }
  63. }
  64.  
  65. for (long x = Int64.MinValue; x < Int64.MaxValue; x++)
  66. {
  67. float r = x;
  68. if (r != x)
  69. {
  70. throw new Exception("Failed at: " + x);
  71. }
  72. }
  73.  
  74. [Exception: not equal 16777217 ?= 1.677722E+07 ?= 16777216]
  75.  
  76. for (int i = 0; i < int.MaxValue; i++)
  77. {
  78. float f = i;
  79. if ((int)f != i) throw new Exception("not equal " + i + " ?= " + f + " ?= " + (int)f);
  80. }
Add Comment
Please, Sign In to add comment