I've recently written a paper outlining the algorithm for determining departure time, arrival time, and flight duration for air travel across multiple time zones, including crossing the International Date Line, going from positive UTC offsets to negative offsets (and reverse), etc. Given any two of these parameters, the third can be calculated based on the three algorithms I've defined. The flight time is given/calculated in decimal hours (e.g. 5.5 hours = 5 hours and 30 minutes, or simply 5:30), and the departure/arrival times are given in military time.

But, I'm uncomfortable with how I've described the modulo operation as needed for the algorithm, based on the fact that I'm using "decimal" numbers.

Here's what my document says:

The modulo operation assumes Euclidian Division extended to decimal (floating-point) numbers. With the divisor always (positive) 24, the result will always be positive. For example, (-15.5) mod 24 = 8.5 whereas 15.5 mod 24 = 15.5.

(NOTE: I was a computer science major with math minor; I'm hoping others here will know what I mean by "floating point".)

My discomfort with the above statement is based on how it seems "improper" to describe modulo on decimal numbers, because (as I understand it) that could possibly be interpreted as real numbers (which include the irrationals). I don't ever remember learning that the modulo function can be applied to ℝ, but my intuition says it can be applied to non-integer ℚ.

My document assumes all flight times will be in fractional hours, but "whole" minutes, thus all "decimaal values" in my document assumes rational numbers only. (Even if they might be infinitely-repeating decimals.) ;-)

How might I re-word the above verbiage to be more accurate, both (English language) semantically and mathematically?


After posting this question, I later realized that a big part of my apprehension lay in the fact that the Wikipedia page mentions three different "types" of division when performing the modulo operation in the context of computer programming, each with a different result when either the dividend or divisor are negative. When composing my document, I felt a bona fide need to qualify which type of division I meant when computing the modulo.

While these represent a wide diversity of mathematical thinking here, I do appreciate the responses.


4 Answers 4


Note that $24\mathbb Z$ is subgroup of abelian group $(\Bbb R,+)$ and thus abelian group $\Bbb R/24\Bbb Z$ can be formed. This will do exactly what you want: $x\equiv y\pmod {24}$ if and only if $x-y\in 24\Bbb Z$, i.e. $x$ and $y$ differ by a multiple of $24$.

Also note that $\Bbb R/24\Bbb Z$ is not a ring, since $24\Bbb Z$ is not ideal in $\Bbb R$ because $\Bbb R$ is a field.

Considering Euclidean division, $\Bbb R$ is a field, and thus trivially Euclidean domain. What I mean is that for $a,b\in\Bbb R$, $b\neq 0$, one can always find $q\in \Bbb R$ such that $a = qb$: namely, $q=\frac a b$.

I'm not sure what exactly you meant by extending Euclidean division, perhaps you wanted $q\in\Bbb Z$? This will yield the same thing as I describe above.

Perhaps it would be beneficial to elaborate what I mean by $\Bbb R/24\Bbb Z$ is abelian group, but not a ring. It boils down to saying that addition is well defined, but multiplication is not. For example take reals $24.1$ and $25.2$. Then we have $$24.1\equiv 0.1\pmod{24}\\ 25.2\equiv 1.2\pmod{24}$$ and if we add the values we have $$24.1+25.2\equiv 0.1+1.2\pmod{24}$$ but $$24.1\cdot 25.2 \not\equiv 0.1\cdot 1.2\pmod{24}$$


There's nothing improper about this function; if your question is just whether or not this is okay mathematically, yes, its perfectly okay.

An explicit definition in terms of the integer floor function is:

$$x \mathbin{\mathrm{mod}} y = x-\lfloor x/y \rfloor \cdot y$$

For instance:

$$(-15.5 \mathbin{\mathrm{mod}} 24) = (-15.5)-(-1)\cdot 24 = -15.5+24 = 8.5$$

Be sure to round down, not toward zero. For example $\lfloor -15.5/24 \rfloor$ should equal $-1$, not $0$.

This defines a perfectly good function $$\mathbb{R} \times \mathbb{R}_{> 0} \rightarrow \mathbb{R}$$ satisfying $(x \mathbin{\mathrm{mod}} y) \in [0,y).$


Definition: If $x,n,r \in \mathbb R$ and $q \in \mathbb Z$ such that $x = qn + r$ and $0 \leq r < n$, then $$x \bmod n = r.$$

For completness you might want to prove that if $x ,n \in \mathbb R$, $n \neq 0$, then there exists $r \in \mathbb R$ such that $x \bmod n = r,$ but I would be willing to accept this assertion without proof. (It is already widely assumed by the definitions of software functions such as the C++ fmod function.)

(I am ignoring the topic of whether the sign of $n$ influences the sign of $r$, since in your case you will set $n=24$, which is positive.)

I think there is no need to restrict the definition to real numbers representable in floating-point notation unless you are going to delve into some details of the numeric calculation that depends on details of the floating-point representation (such as numerical errors).


I'm not sure byt maybe such a definition is correct.

For $x \in \mathbb{R}, \, n \in \mathbb{N}$ let's call $x \pmod n = \min \{y \in \mathbb{R}^+:\, (x-y) \in \mathbb{N} \; \text{and}\; n | (x-y) \}$


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.