Ask Your Question
0

frac is negative when argument is less than zero

asked 2025-07-08 14:40:14 +0200

david_g gravatar image

Hello,

I tried plotting the frac function on sagecell and it behaves as expected where frac(x) = x-floor(x). I.E. frac is positive even when its argument is negative.

However on my local installation, plotting frac (plot(frac,-2,2)) outputs the same thing as plot(sign(x)*frac(abs(x)),-2,2).

I'm on debian 12 and sage version 9.5.

edit retag flag offensive close merge delete

Comments

I'm a little reluctant to do that just yet because my version is closing in on three years old.

david_g gravatar imagedavid_g ( 2025-07-08 16:20:25 +0200 )edit

You can try the current version at https://sagecell.sagemath.org/

Max Alekseyev gravatar imageMax Alekseyev ( 2025-07-08 18:36:37 +0200 )edit

It works for me with the latest version of Sage (the two functions you provide have different plots, and frac is never negative), so you should upgrade.

John Palmieri gravatar imageJohn Palmieri ( 2025-07-14 22:18:01 +0200 )edit

In Sage 10.7beta4 I see:

sage: frac(-2.3)
-0.300000000000000
Max Alekseyev gravatar imageMax Alekseyev ( 2025-07-14 22:34:15 +0200 )edit

@MaxAlekseyev: the question was about plotting, not about this particular evaluation of the frac function. Sage does not seem to behave consistently.

John Palmieri gravatar imageJohn Palmieri ( 2025-07-15 00:32:29 +0200 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2025-07-15 00:31:06 +0200

Here is what I see with sage-10.7.beta8: image description

(For what it's worth, frac(-2.3) outputs -0.300000000000000.)

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

Stats

Asked: 2025-07-08 14:40:14 +0200

Seen: 1,405 times

Last updated: Jul 15