Cg Toolkit Cg 3.1 Toolkit Documentation

Name

round - returns the rounded value of scalars or vectors

Synopsis

float  round(float  a);
float1 round(float1 a);
float2 round(float2 a);
float3 round(float3 a);
float4 round(float4 a);

half   round(half  a);
half1  round(half1 a);
half2  round(half2 a);
half3  round(half3 a);
half4  round(half4 a);

fixed  round(fixed  a);
fixed1 round(fixed1 a);
fixed2 round(fixed2 a);
fixed3 round(fixed3 a);
fixed4 round(fixed4 a);

Parameters

a
Scalar or vector.

Description

Returns the rounded value of a scalar or vector.

For vectors, the returned vector contains the rounded value of each element of the input vector.

The round operation returns the nearest integer to the operand. The value returned by round() if the fractional portion of the operand is 0.5 is profile dependent. On older profiles without built-in round() support, round-to-nearest up rounding is used. On profiles newer than fp40/vp40, round-to-nearest even is used.

Reference Implementation

round for float could be implemented this way:

// round-to-nearest even profiles
float round(float a)
{
  float x = a + 0.5;
  float f = floor(x);
  float r;
  if (x == f) {
    if (a > 0)
      r = f - fmod(f, 2);
    else
      r = f + fmod(f, 2);
  } else
    r = f;
  return r;
}

// round-to-nearest up profiles
float round(float a)
{
  return floor(x + 0.5);
}

Profile Support

round is supported in all profiles except fp20.

See Also

ceil, floor, fmod, trunc


Cg Toolkit | Cg Toolkit | Download | Release Archive | Profiles | Reference | Books | Discussions |


Cg Standard Library

abs
acos
all
any
asin
atan2
atan
bitCount
bitfieldExtract
bitfieldInsert
bitfieldReverse
ceil
clamp
clip
cosh
cos
cross
ddx
ddy
degrees
determinant
distance
dot
exp2
exp
faceforward
findLSB
findMSB
floatToIntBits
floatToRawIntBits
floor
fmod
frac
frexp
fwidth
intBitsToFloat
inverse
isfinite
isinf
isnan
ldexp
length
lerp
lit
log10
log2
log
max
min
modf
mul
normalize
pack
pow
radians
reflect
refract
round
rsqrt
saturate
sign
sincos
sinh
sin
smoothstep
sqrt
step
tanh
tan
tex1DARRAYbias
tex1DARRAYcmpbias
tex1DARRAYcmplod
tex1DARRAYfetch
tex1DARRAYlod
tex1DARRAY
tex1DARRAYproj
tex1DARRAYsize
tex1Dbias
tex1Dcmpbias
tex1Dcmplod
tex1Dfetch
tex1Dlod
tex1D
tex1Dproj
tex1Dsize
tex2DARRAYbias
tex2DARRAYfetch
tex2DARRAYlod
tex2DARRAY
tex2DARRAYproj
tex2DARRAYsize
tex2Dbias
tex2Dcmpbias
tex2Dcmplod
tex2Dfetch
tex2Dlod
tex2DMSARRAYfetch
tex2DMSARRAYsize
tex2DMSfetch
tex2DMSsize
tex2D
tex2Dproj
tex2Dsize
tex3Dbias
tex3Dfetch
tex3Dlod
tex3D
tex3Dproj
tex3Dsize
texBUF
texBUFsize
texCUBEARRAYbias
texCUBEARRAYlod
texCUBEARRAY
texCUBEARRAYsize
texCUBEbias
texCUBElod
texCUBE
texCUBEproj
texCUBEsize
texRBUF
texRBUFsize
texRECTbias
texRECTfetch
texRECTlod
texRECT
texRECTproj
texRECTsize
transpose
trunc
unpack