Jump to content
Joao Lira

'Floating point division by zero' when running script

Recommended Posts

Posted (edited)



I am starting playing with 'P4D', and I am using 'PyScripter' to test the scripts that I'll eventually use in my Delphi applications. I have some questions because of an error I got when running one script:


1) Is 'Demo01' supposedly to run without problems every script that you can run through 'PyScripter'? I have a script that runs flawlessly on 'PyScripter' but it is raising 'Floating point division by zero' error when running with 'Demo01' on 'P4D';

2) Is there some limitation on the scripts that 'P4D' can execute?

I am using Delphi 10.3.3


Thank you for any help.



  Joao Lira.

2022-01-06_112654 - Floating point division by zero error.jpg

Edited by Joao Lira

Share this post

Link to post

This is just going to be the age old issue that most Windows code expects floating point exceptions to be masked, and Delphi's RTL unmasks them. So, mask floating point exceptions when you call into Python, and unmask them when the Python call returns. Or just mask them always if you don't care about floating point exceptions.


Of course, the floating point support for changing floating point control state is not thread safe in the Delphi RTL as I have been saying for more than a decade now.

  • Like 3

Share this post

Link to post


9 hours ago, David Heffernan said:

mask floating point exceptions when you call into Python,

P4D provides the MaskFPUExceptions function for that purpose.

  • Like 1

Share this post

Link to post

Thank you, David and pyscripter!


I didn't know about this 'MaskFPUExceptions procedure. I am still studying 'P4D', so I will take a while to use it without consulting the available stuff about it.  I like demos as a complement to new knowledge, but I learn more when I read, haha! Is there some book you wrote and we can purchase about 'Python4Delphi' pyscripter? Have you thought about it as a way to support even more this GREAT project? 'Python4Delphi' is, without doubt, one of the GREAT pieces of Delphi software EVER! Kudos to you!

After calling 'MaskFPUExceptions' before and after the 'PythonEngine1.ExecString' it worked as expected!



Joao Lira.

Share this post

Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now