First time here? Check out the FAQ!

Ask Your Question
1

Unable to convert string to rational when plus sign is added

asked 5 years ago

Jose Brox gravatar image

updated 5 years ago

This looks like a bug. The code

QQ('+1')

gives the exception

TypeError: unable to convert '+1' to a rational

This happens with any positive rational, not just 1.

Also, this does not happen with neither

ZZ('+1')

nor

PolynomialRing(QQ,names='x')('+1')

Is this actually a bug? If it is, can someone investigate it and write a trac ticket? I'm quite new to Sagemath and Python and quite unskilled yet to do it properly. Thank you!

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
2

answered 5 years ago

As far as I can tell, Sage uses gmp(https://gmplib.org) to construct its rational numbers, and the gmp function mpq_set_strdoesn't handle the leading plus sign. In any case, I would call it a lack of a feature rather than a bug. I've opened https://trac.sagemath.org/ticket/29006.

Preview: (hide)
link

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 5 years ago

Seen: 779 times

Last updated: Jan 14 '20