Oxygen Basic

Programming => Bugs & Feature Requests => Topic started by: Brian Alvarez on February 21, 2020, 01:13:49 AM

Title: Problem with pow
Post by: Brian Alvarez on February 21, 2020, 01:13:49 AM

The following code:

Code: [Select]
DOUBLE d = -2.5654885563273315
print pow(d, 2)

In 32bit outputs  6.581731532646495
In 64bit outputs  -6.5817313194274902

The following does not compile:
Code: [Select]
pow(-2.5654885563273315, 2)
Code: [Select]
ERROR: ERROR: unexpected comma in array index
WORD: -
Title: Re: Problem with pow
Post by: Aurel on February 21, 2020, 02:35:26 AM
Hi Brian
for me work this:

print -2.5654885563273315 ^ 2

but for pow() o2 say - unindentified instruction !
Title: Re: Problem with pow
Post by: Aurel on February 21, 2020, 04:10:44 AM
Hi
here is a quick solution  :D

Code: [Select]
'simple power func
function power(double num,int exponent) as double
double res
res = num ^ exponent
return res
end function

'test
print power(-2.5654885563273315,2)
Title: Re: Problem with pow
Post by: Brian Alvarez on February 21, 2020, 01:23:25 PM
Nice! It works. WHat version are you using Aurel? SQR() is also giving me trouble.
Title: Re: Problem with pow
Post by: Brian Alvarez on February 21, 2020, 03:24:59 PM
made my own.

Code: [Select]
    MACRO SQR extended(r, v)
        r = (v) ^ 0.5
    END MACRO
Title: Re: Problem with pow
Post by: Charles Pegge on February 22, 2020, 03:23:24 AM

pow (and mod) can also be used as operators, without the prolems you report, Brian. Iwill need to investigate further...

What is the problem with sqr ?
Title: Re: Problem with pow
Post by: Brian Alvarez on February 22, 2020, 01:07:52 PM

the problem is that in 64bit gives a different result than in 32bit.
Title: Re: Problem with pow
Post by: Charles Pegge on February 22, 2020, 02:05:18 PM
Deleting all the deff blocks in RTL63.inc should clear the pow sign problem

sqrt should be okay. it uses the fsqrt instruction and only depends on the precision of the parameter pssed to it.
Title: Re: Problem with pow
Post by: Aurel on February 22, 2020, 11:27:13 PM
Quote
WHat version are you using Aurel?

I use 0.2.8. 32bit
Title: Re: Problem with pow
Post by: Brian Alvarez on February 23, 2020, 02:38:21 PM
Where did you get it from? I have 0.2.6 and i cant find any newer....
Title: Re: Problem with pow
Post by: jack on February 23, 2020, 07:07:49 PM
hello Brian
from Charles Pegge's signature address get OxygenBasicProgress.zip
Title: Re: Problem with pow
Post by: Arnold on February 24, 2020, 12:24:04 AM
Hi Brian,

in Github at the moment there is OxygenBasicProgress.zip, OxygenProgress.zip, latest commit 5 months ago. Perhaps you applied OxygenBasic.zip or Oxygen.zip, latest commit 7 months ago? I assume Charles will provide a more recent version anyway in the near future after resolving some of the requests.
Title: Re: Problem with pow
Post by: Aurel on February 24, 2020, 09:24:34 AM
Yes there is on github..
I just look into Oxygen Basic page and found topic GAMES..
i don't know that even exist ..there are games of our old friend Peter Wirbelauer
( i miss that guy ,,,)
and download pac3D...well really nice game ...uffff
i must made one too...but first i must re-learn few things again  ::)
Title: Re: Problem with pow
Post by: Brian Alvarez on February 28, 2020, 08:55:55 PM
I started having issues after i modified my MOD function. I tried:

Code: [Select]
%def ¤MOD mod
but was giving #qNaN with some parameters... i had to roll back to:

Code: [Select]
MACRO ¤MOD quad(r, v, e)
    r = mod(v, e)
END MACRO


Title: Re: Problem with pow
Post by: Charles Pegge on February 29, 2020, 07:14:06 AM
I fixed the65bit sign prolem by removing the deff blocks from RTL64.inc.

These should work:

Code: [Select]
$filename "o.exe"
'uses RTL64
double p = pow(-2.5,2)
print 0 + pow(-2.5,2)
print "" + pow(-2.5,2)
print (pow(-2.5,2))
print -2.5 pow 2
print -2.5 ^ 2

0.2.9 coming soon..
Title: Re: Problem with pow
Post by: Brian Alvarez on March 01, 2020, 06:17:39 AM
Charles, the macro functions like this:

Code: [Select]
MACRO ¤MOD quad(r, v, e)
    r = mod(v, e)
END MACRO


Fail to compile when the invocation contains a parameter with empty brackets like this:

Code: [Select]
print ¤MOD(something(), 2)
Code: [Select]
ERROR: ERROR: Undefined Symbol: )
WORD: 0

Do you think it would be possible to take a look into it before the next update?
Title: Re: Problem with pow
Post by: Brian Alvarez on March 01, 2020, 06:30:32 AM
Seems like it only happens with #if

Code: [Select]
MACRO ¤EXAMPLE string(r, dd, d2)
    #if typecodeof(dd) = 0x68
        r = str(dd)
    #endif
END MACRO


Title: Re: Problem with pow
Post by: Charles Pegge on March 01, 2020, 10:32:32 AM
Brian,

I will extend typeof and typecodeof to support arrays and functions
Title: Re: Problem with pow
Post by: Brian Alvarez on March 01, 2020, 11:52:33 AM
Thanks Charles.  :) I tried passing the function without the empty brackets, but then it complained about the comma right after the function, so the brackets were necessary.
Title: Re: Problem with pow
Post by: Charles Pegge on March 02, 2020, 03:39:07 AM
That is quite simple to fix, Brian, but supposing you pass a polymorphic-function or object-method in dd... I need to think deeper.
Title: Re: Problem with pow
Post by: Brian Alvarez on March 02, 2020, 01:30:21 PM
That is perfect Charles. I need to select wich function to invoke manually because under some circumstances, the function overflow likes to invoke str() as if it was a floating value with integer values, and returns 0.9999999999999 instead of 1.