Ask Your Question
0

How to keep my real numbers rounded

asked 2015-11-09 18:44:41 +0200

Erel Segal-Halevi gravatar image

The following code:

var('t')
test(x) = e^(x * t)
test(0.326)

gives:

e^(0.326000000000000*t)

For some reason, Sage converted my "0.326" to "0.326000000000000".

I want to keep the number rounded. i.e:

e^(0.326*t)

I don't even care if Sage rounds it like this:

e^(0.33*t)

How can I do this?

I know it is possible to use fractions, E.g, I can use "326/1000" instead of "0.326", but this doesn't look good. All I want is that the floating point numbers remain rounded.

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

answered 2015-11-09 19:10:52 +0200

FrédéricC gravatar image

Maybe like that

sage: myR=RealField(12)
sage: var('t')
t
sage: test(x) = e^(x * t)
sage: test(myR(0.326))
e^(0.326*t)
edit flag offensive delete link more

Comments

OK. So I have to convert each real number to the field "real number with 12 bit precision"?

Erel Segal-Halevi gravatar imageErel Segal-Halevi ( 2015-11-11 18:43:53 +0200 )edit

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: 2015-11-09 18:44:41 +0200

Seen: 239 times

Last updated: Nov 09 '15