Ask Your Question
1

Unable to convert string to rational when plus sign is added

asked 2020-01-13 23:24:53 +0100

Jose Brox gravatar image

updated 2020-01-13 23:26:25 +0100

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!

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
2

answered 2020-01-14 05:46:40 +0100

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.

edit flag offensive delete link more

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: 2020-01-13 23:24:53 +0100

Seen: 724 times

Last updated: Jan 14 '20