@@ -124,7 +124,7 @@ cdef class fq_default_ctx:
124124
125125 `var` is a name for the ring generator of this field over GF(p).
126126
127- The optional parameter `type` select the implementation. For more
127+ The optional parameter `type` select the implementation. For more
128128 information about the types available, see :method:`~.fq_type`.
129129 """
130130 # c_from_order expects the characteristic to be fmpz type
@@ -164,7 +164,7 @@ cdef class fq_default_ctx:
164164
165165 `var` is a name for the ring generator of this field over the prime field.
166166
167- The optional parameter `type` select the implementation. For more
167+ The optional parameter `type` select the implementation. For more
168168 information about the types available, see :method:`~.fq_type`.
169169 """
170170 if check_modulus and not modulus.is_irreducible():
@@ -329,16 +329,19 @@ cdef class fq_default_ctx:
329329 return 0
330330
331331 cdef set_any_scalar_as_fq_default(self , fq_default_t fq_ele, obj):
332+ cdef slong i
332333 if typecheck(obj, int ):
333334 # For small integers we can convert directly
334- if obj < 0 and obj.bit_length() < 31 :
335- fq_default_set_si(fq_ele, < slong> obj, self .val)
336- elif obj > 0 and obj.bit_length() < 32 :
337- fq_default_set_ui(fq_ele, < ulong> obj, self .val)
338- # For larger integers we first convert to fmpz
339- else :
340- obj_fmpz = any_as_fmpz(obj)
341- fq_default_set_fmpz(fq_ele, (< fmpz> obj_fmpz).val, self .val)
335+ try :
336+ i = obj
337+ fq_default_set_si(fq_ele, i, self .val)
338+ return 0
339+ # For larger integers fall through to conversion to fmpz
340+ except OverflowError :
341+ pass
342+
343+ obj_fmpz = any_as_fmpz(obj)
344+ fq_default_set_fmpz(fq_ele, (< fmpz> obj_fmpz).val, self .val)
342345 return 0
343346
344347 # For fmpz we can also convert directly
0 commit comments