Python issue with implicit data types
|
08-01-2024, 11:08 AM
Post: #1
|
|||
|
|||
Python issue with implicit data types
I'm currently experiencing Python on a HP Prime and I converted a HPPL Mandelbrot program to python (HPPL wrapper). Python does not seem to declare variables with an explicit data type. It seems just to assume a proper type and it seems to convert from type to type if necessary. I took me hours to get into the following issue:
The Mandelbrot program calculates three colors R, G, B using math functions like sin(). So, the result is a float variable in the range of zero to 255. I want to draw a point with the calculated color and want to pass it to the pixon() function. So, I need a 24-bit color value which I thought I can calculate as col = (R*256 + G)*256 + B I used this value with pixon() but the colors of the Mandelbrot picture are messed up then. pixon() doesn't seem to handle a float color variable correctly although the value itself is the correct color value. I changed the color calculation to: col = (int(R)*256 + int(G))*256 + int(B) and the picture is drawn with correct colors. My first question: Is it true that pixon() and probably other python drawing functions make a difference whether the color parameter is float or integer? Is this probably a bug? The other question I have is, how can I handle implicit and probably unwanted type conversions in python. |
|||
« Next Oldest | Next Newest »
|
Messages In This Thread |
Python issue with implicit data types - 34C - 08-01-2024 11:08 AM
RE: Python issue with implicit data types - nbc12 - 08-01-2024, 08:13 PM
RE: Python issue with implicit data types - bxparks - 08-01-2024, 09:33 PM
RE: Python issue with implicit data types - toml_12953 - 08-01-2024, 09:23 PM
RE: Python issue with implicit data types - Albert Chan - 08-02-2024, 04:13 PM
RE: Python issue with implicit data types - 34C - 08-03-2024, 09:25 AM
|
User(s) browsing this thread: 1 Guest(s)