Page 1 of 1

No Float / No double / WHY ERROR?

Posted: Mon Nov 11, 2024 10:25 pm
by Randy Walker
Windows PB v4.60 and up all complain about a float or double but there is no such thing in this formula, so why the error?

Code: Select all

DSTday = upperBase - (Int(1 + (YIQ + offset) * 5 / 4) % 7) + (7 * (Sign(upperBase/23) * Sign( Int((Int(1 + (YIQ + offset) * 5 / 4) % 7)/(upperBase+7-LDM)) )) )

Re: No Float / No double / WHY ERROR?

Posted: Mon Nov 11, 2024 11:07 pm
by RASHAD
Hi Randy
Result = Int(Number.f(.d))
Result = Sign(Number.f(.d))

Re: No Float / No double / WHY ERROR?

Posted: Mon Nov 11, 2024 11:57 pm
by Randy Walker
RASHAD wrote: Mon Nov 11, 2024 11:07 pm Hi Randy
Result = Int(Number.f(.d))
Result = Sign(Number.f(.d))
Huh??? Your code sample has very distinctive .f (float) but my code uses 4 or 8 byte integer default, depending on PB version.

Re: No Float / No double / WHY ERROR?

Posted: Tue Nov 12, 2024 2:41 am
by TassyJim
The function INT() expects a float so all variables within the function parameters are internally converted to floats. That is why the % function gets upset.
You can break the formula up to avoid the error.

Code: Select all

x =  (Int(1 + (YIQ + offset) * 5 / 4) % 7)/(upperBase+7-LDM)
DSTday = upperBase - (Int(1 + (YIQ + offset) * 5 / 4) % 7) + (7 * (Sign(upperBase/23) * Sign(Int( x) )) )
The int() in the first line is OK because the % is outside the int() brackets.
I am not sure if you can call this a 'bug' or a 'feature' of PureBasic.

Jim

Re: No Float / No double / WHY ERROR?

Posted: Tue Nov 12, 2024 5:53 am
by Randy Walker
TassyJim wrote: Tue Nov 12, 2024 2:41 am The function INT() expects a float so all variables within the function parameters are internally converted to floats. That is why the % function gets upset.

The int() in the first line is OK because the % is outside the int() brackets.
I am not sure if you can call this a 'bug' or a 'feature' of PureBasic.

Jim
Hi Jim,

OK, so I deleted the words Int and Int from the equation, leaving the parentheses in place but got the same exact error, so it can't be solely the Int() function causing the issue. Something else going on there.

Re: No Float / No double / WHY ERROR?

Posted: Tue Nov 12, 2024 5:58 am
by TassyJim
sign() does the same thing. It converts to floats so cannot contain % within the brackets.
An intermediate variable is the only way around the issue as far as I can see.

Re: No Float / No double / WHY ERROR?

Posted: Tue Nov 12, 2024 7:38 am
by Randy Walker
TassyJim wrote: Tue Nov 12, 2024 5:58 am sign() does the same thing. It converts to floats so cannot contain % within the brackets.
An intermediate variable is the only way around the issue as far as I can see.
OK, so the sign() is the "something else going on".
Yes I had already broken the one liner down into multiple lines in my original code:
viewtopic.php?p=409551&hilit=DSTday+%3D ... et#p409551
Look for Procedure DSTformula(
Recently ran into some inconsistencies so I am backtracking to try to figure out where the code jumps off track. Developed the formula and code before my brain surgery and now its like trying to read greek.