How to make the range of modulo $p$ to $[-\frac{p}{2};\frac{p}{2}]$? I am using NTL (A Library for doing Number Theory) to implement a FHE (Fully Homomorphic Encryption) scheme. In general, the range of modulo p is  $[-\frac{p}{2};\frac{p}{2}]$ in FHE scheme. However, the range of modulo p is  $[-p,p]$ in NTL.

If I want to use the range that is $[-\frac{p}{2};\frac{p}{2}]$, how I can do it ?
If the value $x$ is in the set $\{0, 1, 2, .., p-1\}$, which is the "natural" set of residues moduli $p$, then, you just have to check if $x$ is greater than $\frac{p}{2}$ and if so, subtract $p$. 

If $x$ does not belong to $\{0, 1, 2, .., p-1\}$, then you can first do the usual modular reduction to transform $x$ in a element of this set and then, do the subtraction if needed.

my_modular(x, p)
    if 0 &lt;= x and x &lt;= p-1
        if x &gt; p/2
            return x - p
        else
            return x
    else
        new_x = x % p # usual modular operation
        return my_modular(new_x, p)


Notice that I am assuming the usual modular operation will not return negative values as you are saying the NTL's mod operation does.

Try to find a modular operation that return values in $\{0, 1, 2, .., p-1\}$.