BRender Technical Reference Manual:4 Data Structures (Alphabetical Reference):br_fraction
Next|Prev|Up
The Integral Type
Arithmetic
Comparison
Conversion
Copy/Assign

# ` br_fraction`

## The Integral Type

The `br_fraction`
138 type can be used to represent numbers in the range [-1,+1)*1. Although used internally, this type is not currently used by the BRender API.

Under the floating point library, `br_fraction`138 is a `float`. Under the fixed point library, `br_fraction`138 is a 16 bit signed fixed point number.

### The `typedef`

(See `scalar.h `for precise declaration)

`float br_fraction Floating point Signed Fraction`

`br_fixed_lsf br_fraction Fixed - Long Signed Fraction (0.15)`

## Arithmetic

No standard operators are supported. Moreover, there are few macros that directly support fractional arithmetic. Convert to `br_scalar`332 and use that type's arithmetic macros instead.

The following macros are provided to assist with fractional vector arithmetic (see `br_fraction`138). In the following macros, arguments `a`, `c`, `e `and `g `are of type `br_fraction`138, `b`, `d`, `f `and `h `are of type `br_scalar`332. The macro computes a `br_scalar`332 result.

````BR_FMAC2(a,b,c,d)`
```
Return the equivalent of `a * b + c * d `.

````BR_FMAC3(a,b,c,d,e,f)`
```
Return the equivalent of `a * b + c * d + e * f `.

````BR_FMAC4(a,b,c,d,e,f,g,h)`
```
Return the equivalent of `a * b + c * d + e * f + g * h `.

## Comparison

Equality and comparison with zero are valid. Other standard comparison operators may be implemented by macros in future versions, but are currently valid.

## Conversion

### From Numeric Constants

````BR_FRACTION(x)`
```
Convert `x `from any numeric constant to `br_fraction`138.

````BR_SCALAR_EPSILON`
```
Smallest positive fractional value.

### From Integral Types

To convert from integral types, use `br_scalar`
332 as an intermediary.

### From `br_scalar`332

```br_fraction BrScalarToFraction(br_scalar s)
```
Converts `s `from `br_scalar`332 to `br_fraction`138. It is up to the application to ensure the value is in the required range.

### To Integral Types

To convert to integral types, use `br_scalar`332 as an intermediary.

### To `br_scalar`332

```br_scalar BrFractionToScalar(br_fraction f)
```
Converts `s `from `br_fraction`138 to `br_scalar`332. It is up to the application to ensure the value is in the required range.

## Copy/Assign

Only assign zero, or fractions. Use conversions in all other cases.

Generated with
CERN WebMaker