Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Check if 2 double are equals
- # IEEE 754 compliant
- [require]
- GLSL >= 1.30
- [vertex shader]
- #version 130
- void main()
- {
- gl_Position = gl_Vertex;
- }
- [fragment shader]
- #version 130
- /* Returns the fraction bits of the double-precision floating-point value `a'.*/
- uvec2 extractFloat64Frac( uvec2 a )
- {
- return uvec2( a.x & 0x000FFFFFu, a.y );
- }
- /* Returns the exponent bits of the double-precision floating-point value `a'.*/
- uint extractFloat64Exp( uvec2 a )
- {
- return (a.x>>20) & 0x7FFu;
- }
- /* Returns 1 if the double-precision floating-point value `a' is equal to the
- * corresponding value `b', and 0 otherwise. The comparison is performed
- * according to the IEEE Standard for Floating-Point Arithmetic.
- */
- bool eq_fp64( uvec2 a, uvec2 b )
- {
- uvec2 aFrac;
- uvec2 bFrac;
- aFrac = extractFloat64Frac( a );
- bFrac = extractFloat64Frac( b );
- if ( ( ( extractFloat64Exp( a ) == 0x7FFu )
- && ( ( aFrac.x | aFrac.y ) != 0u ) )
- || ( ( extractFloat64Exp( b ) == 0x7FFu )
- && ( ( bFrac.x | bFrac.y ) != 0u ) )
- ) {
- return false;
- }
- return ( a.y == b.y )
- && ( ( a.x == a.x )
- || ( ( a.y == 0u )
- && ( ( ( a.x | b.x )<<1) == 0u ) )
- );
- }
- uniform uvec2 a;
- uniform uvec2 b;
- uniform bool expected;
- void main()
- {
- /* Generate green if the expected value is producted, red
- * otherwise.
- */
- gl_FragColor = eq_fp64(a,b) == expected
- ? vec4(0.0, 1.0, 0.0, 1.0)
- : vec4(1.0, 0.0, 0.0, 1.0);
- }
- [test]
- # A bunch of tests to run. The 'uniform' lines set the uniforms. The
- # 'draw rect' line draws a rectangle that covers the whole window.
- # The 'probe all' line verifies that every pixel contains the expected
- # color.
- # Try +0.0 and +0.0
- uniform uvec2 a 0x00000000 0x00000000
- uniform uvec2 b 0x00000000 0x00000000
- uniform bool expected true
- draw rect -1 -1 2 2
- probe all rgba 0.0 1.0 0.0 1.0
- # Try -0.0 and +0.0
- uniform uvec2 a 0x10000000 0x00000000
- uniform uvec2 b 0x00000000 0x00000000
- uniform bool expected true
- draw rect -1 -1 2 2
- probe all rgba 0.0 1.0 0.0 1.0
- # Try 0.1 and 0.0
- uniform uvec2 a 0x3FB99999 0x9999999A
- uniform uvec2 b 0x00000000 0x00000000
- uniform bool expected false
- draw rect -1 -1 2 2
- probe all rgba 0.0 1.0 0.0 1.0
- # Try 1 bit set and 0.0
- uniform uvec2 a 0x00000000 0x00000001
- uniform uvec2 b 0x00000000 0x00000000
- uniform bool expected false
- draw rect -1 -1 2 2
- probe all rgba 0.0 1.0 0.0 1.0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement