Advertisement
Guest User

Untitled

a guest
Jul 26th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1. # Check if 2 double are equals
  2. # IEEE 754 compliant
  3.  
  4. [require]
  5. GLSL >= 1.30
  6.  
  7. [vertex shader]
  8. #version 130
  9.  
  10. void main()
  11. {
  12. gl_Position = gl_Vertex;
  13. }
  14.  
  15. [fragment shader]
  16. #version 130
  17.  
  18. /* Returns the fraction bits of the double-precision floating-point value `a'.*/
  19. uvec2 extractFloat64Frac( uvec2 a )
  20. {
  21. return uvec2( a.x & 0x000FFFFFu, a.y );
  22. }
  23.  
  24. /* Returns the exponent bits of the double-precision floating-point value `a'.*/
  25. uint extractFloat64Exp( uvec2 a )
  26. {
  27. return (a.x>>20) & 0x7FFu;
  28. }
  29.  
  30. /* Returns 1 if the double-precision floating-point value `a' is equal to the
  31. * corresponding value `b', and 0 otherwise. The comparison is performed
  32. * according to the IEEE Standard for Floating-Point Arithmetic.
  33. */
  34. bool eq_fp64( uvec2 a, uvec2 b )
  35. {
  36. uvec2 aFrac;
  37. uvec2 bFrac;
  38.  
  39. aFrac = extractFloat64Frac( a );
  40. bFrac = extractFloat64Frac( b );
  41. if ( ( ( extractFloat64Exp( a ) == 0x7FFu )
  42. && ( ( aFrac.x | aFrac.y ) != 0u ) )
  43. || ( ( extractFloat64Exp( b ) == 0x7FFu )
  44. && ( ( bFrac.x | bFrac.y ) != 0u ) )
  45. ) {
  46. return false;
  47. }
  48. return ( a.y == b.y )
  49. && ( ( a.x == a.x )
  50. || ( ( a.y == 0u )
  51. && ( ( ( a.x | b.x )<<1) == 0u ) )
  52. );
  53. }
  54.  
  55. uniform uvec2 a;
  56. uniform uvec2 b;
  57. uniform bool expected;
  58.  
  59. void main()
  60. {
  61. /* Generate green if the expected value is producted, red
  62. * otherwise.
  63. */
  64. gl_FragColor = eq_fp64(a,b) == expected
  65. ? vec4(0.0, 1.0, 0.0, 1.0)
  66. : vec4(1.0, 0.0, 0.0, 1.0);
  67. }
  68.  
  69. [test]
  70. # A bunch of tests to run. The 'uniform' lines set the uniforms. The
  71. # 'draw rect' line draws a rectangle that covers the whole window.
  72. # The 'probe all' line verifies that every pixel contains the expected
  73. # color.
  74.  
  75. # Try +0.0 and +0.0
  76. uniform uvec2 a 0x00000000 0x00000000
  77. uniform uvec2 b 0x00000000 0x00000000
  78. uniform bool expected true
  79. draw rect -1 -1 2 2
  80. probe all rgba 0.0 1.0 0.0 1.0
  81.  
  82. # Try -0.0 and +0.0
  83. uniform uvec2 a 0x10000000 0x00000000
  84. uniform uvec2 b 0x00000000 0x00000000
  85. uniform bool expected true
  86. draw rect -1 -1 2 2
  87. probe all rgba 0.0 1.0 0.0 1.0
  88.  
  89. # Try 0.1 and 0.0
  90. uniform uvec2 a 0x3FB99999 0x9999999A
  91. uniform uvec2 b 0x00000000 0x00000000
  92. uniform bool expected false
  93. draw rect -1 -1 2 2
  94. probe all rgba 0.0 1.0 0.0 1.0
  95.  
  96. # Try 1 bit set and 0.0
  97. uniform uvec2 a 0x00000000 0x00000001
  98. uniform uvec2 b 0x00000000 0x00000000
  99. uniform bool expected false
  100. draw rect -1 -1 2 2
  101. probe all rgba 0.0 1.0 0.0 1.0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement