I don't think this is a bug that Sage can fix.  When you execute
RR(8059/9042) in Python, it first evaluates 8059/9042 which produces a
float, then passes that to RR.  There's no way for RR to know that you
initially input a ratio of ints.
David

On Mon, Apr 10, 2023 at 4:11 PM aw <aw.phone.00...@gmail.com> wrote:

> when passing python ints to realfield, they don't get cast to sage integers
> this can cause wrong answers
>
> example:
>
> RR=RealField(100)
>
> set_random_seed(3)
> n1=randint(1000,9999)    #n1=8059
> n2=randint(1000,9999)    #n2=9042
> print(n1,'/',n2,'=',sep='')
> print(RR(n1/n2))                #passing as 8059,9042 as python ints
>
> print()
>
> print(8059,'/',9042,'=',sep='')
> print(RR(8059/9042))      #passing 8059,9042 as sage ints
>
>
> output:
>
> 8059/9042=
> 0.89128511391285114573435066632
>
> 8059/9042=
> 0.89128511391285113912851139128
>
> the first one is wrong, the second one is right
>
> this bug is trivial to fix
> when ints are passed to realfield, they should be automatically cast to
> sage ints
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "sage-devel" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sage-devel+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sage-devel/8bacb253-6d1c-4508-8b79-82ce7aea0caen%40googlegroups.com
> <https://groups.google.com/d/msgid/sage-devel/8bacb253-6d1c-4508-8b79-82ce7aea0caen%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-devel/CAChs6_kH%2BHj599PMfS3WsO995Q_RE_ZEfV4zrT58JZb69foKBA%40mail.gmail.com.

Reply via email to