1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//
// GENERATED FILE
//
use super::*;
use f2rust_std::*;
//$Procedure ZZSIZEOK ( Determine if the size of a segment is ok )
pub fn ZZSIZEOK(
SIZE: i32,
PSIZE: i32,
DSIZE: i32,
OFFSET: i32,
OK: &mut bool,
N: &mut i32,
ctx: &mut Context,
) -> f2rust_std::Result<()> {
let mut Q: i32 = 0;
let mut PD1: i32 = 0;
let mut R: i32 = 0;
let mut A: i32 = 0;
//
// Here's the scoop.
//
// Suppose N is a solution to SIZE = PSIZE*N + (N-OFFSET)/DSIZE
// N can be represented uniquely as
//
// N = q*DSIZE + r
//
// where OFFSET <= r <= DSIZE+OFFSET-1. Therefore there must
// be values q and r such that
//
// SIZE = PSIZE*(q*DSIZE + r ) + ( q*DSIZE + r - 1 ) / DSIZE
//
// = PSIZE*DSIZE*q + q + PSIZE*r
//
// = (PSIZE*DSIZE+1)*q + PSIZE*r
//
// But SIZE can be represented uniquely as
//
// SIZE = (PSIZE*DSIZE+1)*k + a
//
// where 0 <= a < (PSIZE*DSIZE+1).
//
// But PSIZE*OFFSET < PSIZE*r < (PSIZE*DSIZE+OFFSET-1),
// therefore it must be that
//
// SIZE mod(PSIZE*DSIZE+1) = PSIZE*r
// and q = k
//
// Hence, there is a solution to our equation if and only if
//
// PSIZE divides SIZE mod(PSIZE*DSIZE+1)
// and OFFSET*PSIZE <= SIZE mod(PSIZE*DSIZE+1)
//
//
// Handle the exceptional case first.
//
if (((SIZE <= 0) || (DSIZE <= 0)) || (PSIZE <= 0)) {
*N = 0;
*OK = false;
return Ok(());
}
PD1 = ((PSIZE * DSIZE) + 1);
RMAINI(SIZE, PD1, &mut Q, &mut A, ctx)?;
if ((OFFSET * PSIZE) > A) {
*N = 0;
*OK = false;
return Ok(());
}
if (A == ((A / PSIZE) * PSIZE)) {
R = (A / PSIZE);
*N = ((DSIZE * Q) + R);
*OK = true;
} else {
*OK = false;
*N = 0;
}
Ok(())
}