v = fmpq[1,0,0] vector,
how to convert this to just [1,0,0]
v = fmpq[1,0,0] vector,
how to convert this to just [1,0,0]
What is fmpq
? Please read:
fmpq = frequently making puzzling questions
if the denominator()
= 1
numerator()
julia> using Nemo
julia> v = fmpq[1,0,0]
3-element Vector{fmpq}:
1
0
0
julia> biv =BigInt[]
BigInt[]
julia> for a in v
n = numerator(a)
d = denominator(a)
if isone(d)
push!(biv, BigInt(n) )
else
println("ouch ..")
end
end
julia> println(biv)
BigInt[1, 0, 0]
hint: if your question is a nemo
related
nemo
tag for your question.See other nemo
related questions:
Nemo types
fmpq
(FlintRationalField
)And you can check the source code
better version
using Nemo
int_numerator_fmpq(v) = ifelse( unique!(denominator.(v)) == [fmpz(1)], Int.(numerator.(v)), missing );
int_numerator_fmpq( fmpq[1,0,0] )
int_numerator_fmpq( fmpq[1//3, 9//2 , 1//1 ] )
int_numerator_fmpq( fmpq[3//3, 999//999, 0//2 ] )
log:
julia> int_numerator_fmpq(v) = ifelse( unique!(denominator.(v)) == [fmpz(1)], Int.(numerator.(v)), missing );
julia> int_numerator_fmpq( fmpq[1,0,0] )
3-element Vector{Int64}:
1
0
0
julia> int_numerator_fmpq( fmpq[1//3, 9//2 , 1//1 ] )
missing
julia> int_numerator_fmpq( fmpq[3//3, 999//999, 0//2 ] )
3-element Vector{Int64}:
1
1
0