|
Post by rosy on Jan 13, 2021 7:15:01 GMT -6
No division by 0 control? What does the value "nan" mean?
|
|
|
Post by Tomaaz on Jan 13, 2021 8:20:33 GMT -6
Not a number?
|
|
|
Post by n00b on Jan 14, 2021 3:36:58 GMT -6
This is not a bug. I would recommend either an If statement to check the number you are dividing by or something like this.
i = 0 x = 5 / Max(i, 0.000001)
Its mathematically impossible to divide by zero and the NAN is how RCBasic deals with this. This will be an error in not just programming but even when using a calculator.
|
|
|
Post by rosy on Jan 14, 2021 4:40:24 GMT -6
But there is no message, and if I put this NAN into another function, miracles are happening and we don't know why ...
|
|
|
Post by n00b on Jan 14, 2021 8:00:38 GMT -6
To have the safest code possible I would recommend always having a test for a divide by 0 case. I usually just have an if statement that checks for it. I think I had to test for that a few times in the 3D maze example and Mode7 example. If you know there is a possibility of division by zero you should test for it. This would also apply to something like finding a square root of a negative number.
|
|
|
Post by tbird on Jan 14, 2021 8:44:29 GMT -6
Sounds like a post for the tips and tricks section, little trip-me's that RC might have compared to other languages that need a little extra programmer effort. I know now I have gotten into the habit of every function I put:
Print "Init Function Foo()" Function Foo() If RCBasic = Awesome Then RCBasicIs$ = "Awesome" Else RCBasicIs$ = "OK" End If End Function Print "End Function Foo()"
You wouldn't believe how many headaches this has saved me lol, this way I know exactly when the program $hit$ the bed.
|
|
|
Post by rosy on Mar 26, 2021 11:07:04 GMT -6
I had a problem with that again. I lost a lot of time, it turned out that the variable takes 0, but the division resulted in zeroing a completely different variable and probably blocking it as well. It can't be so ... You said it was written in C, and after all C throws an error dividing by 0, not some miracle ...
|
|
|
Post by aurel on Mar 26, 2021 11:31:40 GMT -6
It is not a bug in real term...but RCbasic expression evaluator should report that as error : Division by Zero! I dont know what type of evaluator nOOb made in RC but this small code present C example:
switch(token)
{
case MULT:
match(MULT);
right = factor();
left *= right;
break;
case DIV:
match(DIV);
right = factor();
if(right != 0.0)
left /= right;
else
seterror(ERR_DIVIDEBYZERO);
break;
case MOD:
match(MOD);
right = factor();
left = fmod(left, right);
break;
default:
return left;
PS..oh crap I also forget to add this in my interpreter !
|
|
|
Post by rosy on Mar 29, 2021 3:08:32 GMT -6
In my opinion, it was enough to transmit error messages reported by C. Some "nan" value is assigned here, but sometimes completely unpredictable things also happen.
|
|
|
Post by rosy on Apr 16, 2021 6:43:16 GMT -6
Rodney, can you further explain the meanders of this math? Because now "inf" appears instead of "nan" and, for example, the ATAN function returns the result of such an argument, although in ordinary mathematics such an argument does not exist ... Or maybe there is ...
|
|
|
Post by kennn on Apr 16, 2021 21:26:32 GMT -6
Rodney, can you further explain the meanders of this math? Because now "inf" appears instead of "nan" and, for example, the ATAN function returns the result of such an argument, although in ordinary mathematics such an argument does not exist ... Or maybe there is ... No response? Maybe Noob is busy in developing a game. (We may see a creative entry from Noob for the game contest.) itch.io/jam/jam-for-all-basic-dialects
|
|
|
Post by n00b on Apr 17, 2021 9:09:42 GMT -6
kennn I don't know if I am going to make a creative entry but it will be better than my last Ludum dare entry. rosy I am not at my computer right now. As soon as I get the chance I will look into your last few post.
|
|
|
Post by kennn on Apr 18, 2021 4:51:12 GMT -6
noob, We hope to see the full potential of RCBasic in this entry.
rosy, If you join the contest as well, we will have a chance to see an entertaining entry from you.
|
|
|
Post by n00b on Apr 19, 2021 21:18:58 GMT -6
Rodney, can you further explain the meanders of this math? Because now "inf" appears instead of "nan" and, for example, the ATAN function returns the result of such an argument, although in ordinary mathematics such an argument does not exist ... Or maybe there is ... ATAN is the built-in ATAN function in the cmath library. Look at documentation on it here: C-Math ATAN description
|
|
|
Post by rosy on Apr 20, 2021 9:49:39 GMT -6
I don't see anything there about "nan" and "inf" ...
Why does division by 0 sometimes return "inf" (which is sometimes OK) and sometimes "nan" and cause additional problems?
By the way, you could add atan2, which in games would probably be more useful than atan.
|
|