Python Forum
How to verify widening conversion?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to verify widening conversion?
#1
I am trying to understand why I can not see int to float widening in Python bytecode.

here is the code:

import dis
dis.dis("5.0 == 5")

Output:
0 0 RESUME 0

1 2 LOAD_CONST 0 (5.0)
4 LOAD_CONST 1 (5)
6 COMPARE_OP 2 (==)
12 RETURN_VALUE

If the widening is not present in the bytecode - is there another way I can verify it?
buran write Apr-08-2023, 06:37 AM:
Please, use proper tags when post code, traceback, output, etc.
See BBcode help for more info.
Reply
#2
(Apr-08-2023, 03:54 AM)quazirfan Wrote: If the widening is not present in the bytecode - is there another way I can verify it?
By widening, I suppose you mean the conversion from int to float that may occur when the expression 5.0 == 5 is evaluated. In CPython, this is done in the C function float_richcompare() of Objects/floatobject.c in the source tree, see the section that starts with else if (PyLong_Check(w)) {.... This part is rather tricky because Python integers can be arbitrary large.
quazirfan likes this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Verify input as integer and not blank GMCobraz 3 2,148 Jun-22-2020, 02:47 PM
Last Post: pyzyx3qwerty
  How to verify the give number is valid Mekala 3 2,412 May-16-2020, 02:40 PM
Last Post: anbu23
  Unable to verify python versio ThereIsNoSpoom 2 1,804 Jan-15-2020, 09:12 AM
Last Post: DeaD_EyE
  Verify if .docx table of contents is updated as per document sections or not vintysaw 0 3,892 Oct-24-2019, 12:01 PM
Last Post: vintysaw

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020