Skip to content

Commit f71ebf4

Browse files
committed
Update fixed-point documentation to reflect deprecation of --fixedbv
Remove references to the deprecated `--fixedbv` command-line option (removed in PR #2148) and document `__CPROVER_fixedbv` as the preferred approach for fixed-point arithmetic Fixes: #6115
1 parent 4fe3ade commit f71ebf4

File tree

1 file changed

+99
-4
lines changed

1 file changed

+99
-4
lines changed

doc/cprover-manual/modeling-floating-point.md

Lines changed: 99 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,104 @@ is unknown.
100100

101101
### Fixed-point Arithmetic
102102

103-
CPROVER also has support for fixed-point types. The `--fixedbv` flag
104-
switches `float`, `double`, and `long double` to fixed-point types. The
105-
length of these types is platform specific. The upper half of each type
106-
is the integer component and the lower half is the fractional part.
103+
CPROVER supports fixed-point arithmetic through the `__CPROVER_fixedbv` type.
104+
This type allows you to specify a fixed-point bit vector with arbitrary but
105+
fixed size. The syntax is:
106+
107+
```C
108+
__CPROVER_fixedbv[width][fraction_bits]
109+
```
110+
111+
where `width` is the total size in bits, and `fraction_bits` is the number of
112+
bits after the radix point. For example, `__CPROVER_fixedbv[32][16]` defines
113+
a 32-bit fixed-point type with 16 bits for the integer part and 16 bits for
114+
the fractional part.
115+
116+
#### Using Fixed-point Types
117+
118+
Fixed-point types can be used with typedefs for convenience:
119+
120+
```C
121+
typedef __CPROVER_fixedbv[32][16] fixed32_t;
122+
123+
fixed32_t x = 10.5;
124+
fixed32_t y = 3.25;
125+
fixed32_t z = x + y;
126+
```
127+
128+
If you need to use fixed-point arithmetic for standard floating-point types
129+
throughout your code, you can use preprocessor definitions:
130+
131+
```C
132+
#define float __CPROVER_fixedbv[32][16]
133+
#define double __CPROVER_fixedbv[64][32]
134+
```
135+
136+
**Note**: The `--fixedbv` command-line option that previously provided similar
137+
functionality was removed in CBMC version 5.9 (see PR #2148). The
138+
`__CPROVER_fixedbv` type is the current and preferred approach for
139+
fixed-point arithmetic.
140+
141+
#### Arithmetic Operations
142+
143+
CPROVER supports the standard arithmetic operators for `__CPROVER_fixedbv`
144+
types:
145+
146+
- **Addition and Subtraction**: Performed directly on the underlying values.
147+
Note that CBMC does not automatically insert overflow checks for fixed-point
148+
addition and subtraction. If overflow checking is required, you must
149+
explicitly add assertions or use `__CPROVER_overflow_plus` and
150+
`__CPROVER_overflow_minus` functions.
151+
152+
- **Multiplication**: When two fixed-point values are multiplied, the result
153+
is computed with extended precision and then rounded back to the target
154+
type. The internal representation is adjusted to account for the combined
155+
width and integer bits of both operands before rounding.
156+
157+
- **Division**: Division is performed by scaling the dividend by an appropriate
158+
power of two based on the fractional bits of the divisor, then performing
159+
integer division. The result maintains the fixed-point representation of the
160+
dividend's type.
161+
162+
- **Comparison operators**: All standard comparison operators (`<`, `<=`, `>`,
163+
`>=`, `==`, `!=`) are supported.
164+
165+
- **Type conversions**: Fixed-point values can be converted to and from
166+
integers and other fixed-point types. Conversions to integers truncate
167+
toward zero (round-to-zero semantics).
168+
169+
#### Math Library and Special Functions
170+
171+
CPROVER does not currently provide built-in support for mathematical functions
172+
(such as trigonometric functions, exponentials, logarithms, or square roots)
173+
for `__CPROVER_fixedbv` types. If you need such functions for your
174+
verification, you have several options:
175+
176+
1. **Provide your own implementations**: You can write approximations of these
177+
functions using fixed-point arithmetic operations.
178+
179+
2. **Use uninterpreted functions**: For abstract reasoning about function
180+
behavior without concrete implementations, you can use CPROVER's
181+
uninterpreted functions (see [Nondeterminism](../../modeling/nondeterminism/)).
182+
183+
3. **Add function stubs with contracts**: Define function stubs with
184+
`__CPROVER_assume` statements to specify the expected behavior of the
185+
function for verification purposes.
186+
187+
Example of providing a simple approximation:
188+
189+
```C
190+
typedef __CPROVER_fixedbv[32][16] fixed32_t;
191+
192+
// User-provided approximation of absolute value
193+
fixed32_t fixed_abs(fixed32_t x) {
194+
return x < 0 ? -x : x;
195+
}
196+
```
197+
198+
#### Additional Information
199+
200+
For more details on the `__CPROVER_fixedbv` type and other CPROVER-specific
201+
types and functions, see the [API Reference](api.md).
107202

108203

0 commit comments

Comments
 (0)