The following warnings occurred:
Warning [2] count(): Parameter must be an array or an object that implements Countable - Line: 795 - File: showthread.php PHP 7.4.33 (FreeBSD)
File Line Function
/showthread.php 795 errorHandler->error





Post Reply 
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.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Python issue with implicit data types - 34C - 08-01-2024 11:08 AM



User(s) browsing this thread: 3 Guest(s)