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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
//
// GENERATED FILE
//
use super::*;
use crate::SpiceContext;
use f2rust_std::*;
/// Remainder --- integer
///
/// Compute the integer quotient and non-negative remainder
/// of NUM and DENOM.
///
/// # Brief I/O
///
/// ```text
/// VARIABLE I/O DESCRIPTION
/// -------- --- --------------------------------------------------
/// NUM I Numerator used to compute quotient and remainder.
/// DENOM I Denominator used to compute quotient and remainder.
/// Q O Integer portion of the quotient NUM/DENOM.
/// REM O Remainder of the quotient NUM/DENOM.
/// ```
///
/// # Detailed Input
///
/// ```text
/// NUM is the numerator of a quotient
///
/// DENOM is the denominator of a quotient
/// ```
///
/// # Detailed Output
///
/// ```text
/// Q is the largest integer less than or equal to the
/// quotient NUM/DENOM
///
/// REM is the remainder of the integer division NUM/DENOM
/// ```
///
/// # Exceptions
///
/// ```text
/// 1) If DENOM is zero, the error SPICE(DIVIDEBYZERO) is signaled.
/// ```
///
/// # Particulars
///
/// ```text
/// Given the integer inputs NUM and DENOM, this routine
/// finds integers Q and REM that satisfy the following conditions:
///
/// 1) NUM = DENOM * Q + REM
///
/// 2) REM is a non negative integer less than the absolute
/// value of DENOM.
///
/// This routine serves as a macro. In this way the code to perform
/// this task can be written and maintained in a single location.
/// ```
///
/// # Examples
///
/// ```text
/// One frequently needs to compute the ``360 modulus'' of a
/// number. For positive numbers the FORTRAN intrinsic mod
/// function works well. However, for negative numbers the
/// intrinsic will return a negative modulus. This routine
/// can be used to compute the positive 360 pi modulus (MOD360) for
/// any integer I by the call:
///
/// CALL RMAINI ( I, 360, Q, MOD360 )
/// ```
///
/// # Author and Institution
///
/// ```text
/// J. Diaz del Rio (ODC Space)
/// W.L. Taber (JPL)
/// ```
///
/// # Version
///
/// ```text
/// - SPICELIB Version 1.1.0, 12-AUG-2021 (JDR)
///
/// Added IMPLICIT NONE statement.
///
/// Edited the header to comply with NAIF standard.
///
/// - SPICELIB Version 1.0.0, 01-DEC-1995 (WLT)
/// ```
pub fn rmaini(
ctx: &mut SpiceContext,
num: i32,
denom: i32,
q: &mut i32,
rem: &mut i32,
) -> crate::Result<()> {
RMAINI(num, denom, q, rem, ctx.raw_context())?;
ctx.handle_errors()?;
Ok(())
}
//$Procedure RMAINI ( Remainder --- integer )
pub fn RMAINI(
NUM: i32,
DENOM: i32,
Q: &mut i32,
REM: &mut i32,
ctx: &mut Context,
) -> f2rust_std::Result<()> {
//
// Take care of the zero-denominator case first
//
if ((DENOM as f64) == 0.0) {
CHKIN(b"RMAINI", ctx)?;
SETMSG(
b"Attempting to compute a quotient with a divide by zero.",
ctx,
);
SIGERR(b"SPICE(DIVIDEBYZERO)", ctx)?;
CHKOUT(b"RMAINI", ctx)?;
return Ok(());
}
*Q = (NUM / DENOM);
*REM = (NUM - (DENOM * *Q));
if (*REM < 0) {
*Q = (*Q - 1);
*REM = (*REM + DENOM);
}
Ok(())
}