No Float / No double / WHY ERROR?

Just starting out? Need help? Post your questions and find answers here.
Randy Walker
Addict
Addict
Posts: 1109
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA

No Float / No double / WHY ERROR?

Post 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)) )) )
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4991
Joined: Sun Apr 12, 2009 6:27 am

Re: No Float / No double / WHY ERROR?

Post by RASHAD »

Hi Randy
Result = Int(Number.f(.d))
Result = Sign(Number.f(.d))
Egypt my love
Randy Walker
Addict
Addict
Posts: 1109
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA

Re: No Float / No double / WHY ERROR?

Post 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.
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
TassyJim
Enthusiast
Enthusiast
Posts: 189
Joined: Sun Jun 16, 2013 6:27 am
Location: Tasmania (Australia)

Re: No Float / No double / WHY ERROR?

Post 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
Randy Walker
Addict
Addict
Posts: 1109
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA

Re: No Float / No double / WHY ERROR?

Post 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.
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
TassyJim
Enthusiast
Enthusiast
Posts: 189
Joined: Sun Jun 16, 2013 6:27 am
Location: Tasmania (Australia)

Re: No Float / No double / WHY ERROR?

Post 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.
Randy Walker
Addict
Addict
Posts: 1109
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA

Re: No Float / No double / WHY ERROR?

Post 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.
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
Post Reply