.
**
** Note that 'POW_FFV' may only be used if the right operand is an integer
-** in the range $0..order(f)-1$.
+** in the range $0..order(f)-1$ (tested by an assertion)
**
** Finally 'POW_FFV' may only be used if the product of two integers of the
-** size of 'FFV' does not cause an overflow, i.e. only if 'FFV' is
-** 'unsigned short'.
+** size of 'FFV' does not cause an overflow. This is tested by a compile
+** -time assertion.
+**
**
** If the finite field element is 0 the power is also 0, otherwise we have
** $a^n ~ (z^{a-1})^n = z^{(a-1)*n} = z^{(a-1)*n % (o-1)} ~ (a-1)*n % (o-1)$
@@ -311,7 +306,7 @@ EXPORT_INLINE FFV POW_FFV(FFV a, UInt n, const FFV * f)
EXPORT_INLINE FF FLD_FFE(Obj ffe)
{
GAP_ASSERT(IS_FFE(ffe));
- return (FF)((((UInt)(ffe)) & 0xFFFF) >> 3);
+ return (FF)((UInt)(ffe) >> 3) & ((1 << FIELD_BITS_FFE) - 1);
}
@@ -327,7 +322,8 @@ EXPORT_INLINE FF FLD_FFE(Obj ffe)
EXPORT_INLINE FFV VAL_FFE(Obj ffe)
{
GAP_ASSERT(IS_FFE(ffe));
- return (FFV)(((UInt)(ffe)) >> 16);
+ return (FFV)((UInt)(ffe) >> (3 + FIELD_BITS_FFE)) &
+ ((1 << VAL_BITS_FFE) - 1);
}
@@ -342,7 +338,8 @@ EXPORT_INLINE FFV VAL_FFE(Obj ffe)
EXPORT_INLINE Obj NEW_FFE(FF fld, FFV val)
{
GAP_ASSERT(val < SIZE_FF(fld));
- return (Obj)(((UInt)(val) << 16) + ((UInt)(fld) << 3) + (UInt)0x02);
+ return (Obj)(((UInt)val << (3 + FIELD_BITS_FFE)) | ((UInt)fld << 3) |
+ (UInt)0x02);
}
diff --git a/tst/testinstall/ffe.tst b/tst/testinstall/ffe.tst
index f14ea02ef0d..715e87f180f 100644
--- a/tst/testinstall/ffe.tst
+++ b/tst/testinstall/ffe.tst
@@ -65,11 +65,11 @@ Error, Z: must be a prime (not the integer 9)
gap> Z(9,2);
Error, Z:
must be a prime (not the integer 9)
gap> Z(2^16,1);
-Error, Z:
must be a prime
+Error, Z:
must be a prime (not the integer 65536)
gap> Z(2^16,2);
Error, Z:
must be a prime
gap> Z(2^17,1);
-Error, Z:
must be a prime
+Error, Z:
must be a prime (not the integer 131072)
gap> Z(2^17,2);
Error, Z:
must be a prime