Oxygen Basic
Programming => Bugs & Feature Requests => Topic started by: Brian Alvarez on March 14, 2020, 08:38:56 PM
-
Hello Charles. I would like if you could please re-download PluriBASIC from the link i sent you, and try this code:
#COMPILE EXE
#COMPILER oxygen
'#COMPILER pbwin
#OPTIONS x32
#DIM ALL
#OPTIONS DEVELOPER
FUNCTION PBMAIN () AS LONG
local vsing as single = 3.141519
local vdoub as double = 3.141519
static vint as long
local vquad as quad = 4989895
local ws as wstring = "0"
local s as string = "$ 0,.00"
'vint += 1 ' i need to fix this.
LOCAL y AS long = 3.7
local z AS double = 12345.12321
incr vint
? FORMAT$(0, ws)
? FORMAT$(2323332.15, s)
? FORMAT$(2323332.15, "0.000")
? str$(2323332.123)
? str$(2323332)
? str$(vint)
? FORMAT$(0)
? FORMAT$(1)
? FORMAT$(vsing)
? FORMAT$(vdoub)
? FORMAT$(vint)
? FORMAT$(vquad)
END FUNCTION
When compiling for 32 bit, the output is just about perfect, but on 64bit mode, something crashes. The culprit is in FORMAT$.bin, you can navigate to Stock > Oxygen > FORMAT$, there is a comment there: fails in 64 bit mode, I dont know why it doesnt work on 64bit mode.
-
This code used to work perfectly too, now it fails even in 32bit mode:
#COMPILE EXE
#COMPILER OXYGEN ' use Oxygen compiler.
'#COMPILER pbwin ' Use PowerBASIC compiler.
#OPTIONS X32 ' You can choose platform here, 32 or 64 bits.
#OPTIONS developer ' The output will be captured in the console output tab.
#DIM ALL
' Note: Click the Console output tab to display the output of this example.
' You can then switch compilers to make sure the output is the same.
' THIS EXAMPLE SHOWCASES THE OUTPUT OF FORMAT$
FUNCTION PBMAIN() AS LONG
' Compare the output of FORMAT$
STDOUT "Compiled with " & EXE.compiler$ & "."
STDOUT
stdout ",12,345,6 7 8.2 = " & FORMAT$(12345678.2238, ",#,# # #.#")
stdout
stdout ",12,345,6 7 8.2 = " & FORMAT$(12345678.2238, ",#, # #.#")
stdout
stdout ",12,345,67 8.2 = " & FORMAT$(12345678.2238, ",#,# #.#")
stdout
stdout ",123456 7 8..2.4 = " & FORMAT$(12345678.2388, ",# # #..#.#")
stdout
stdout " 23 2 1.8 = " & FORMAT$(2321.75, " # # #.#")
stdout
stdout " XYZ=5.55# = " & FORMAT$(5.55, "HELLO !""XYZ=""#.##\#")
stdout
stdout " 0000010 = " & FORMAT$(10, "0000000")
stdout
stdout "++--20-.$0.0% = " & FORMAT$(1 / 5!, "++--*+,-./$0.0%")
stdout "-100 = " & FORMAT$(-100, "+00000.00;-000")
END FUNCTION
-
This last example works if i remove the optional wstring overflow functions.
-
New version seems to behave better but still not sure how to work with unicode.
-
I think the culprit is that the overflow functions are picking short for long (using long instead of int does not fix it)... take a look at the attached picture:
-
I finally made a version that works with all datatypes, all string types and for 32bit and 64 bits. :)
-
Hi Brian,
I don't know what your format function does but I made one for rounding decimal places that runs with your first example. The number is autoconverted into a string so there are no type limitations.
Quad math is processed in the FPU in both 32bit and 64bit modes. But quad returns from functions are not correct in the upper 32bits in 64bit mode. This will be fixed in version 0.2.9
$filename "o.exe"
uses rtl64
uses console
def str$ str
def incr inc
def p? printl
function format$(string n, optional string f) as string
if f
int i=instr(f,".")
if i 'count places to right
int j=len(f)
int k=j-i
if k>0 'decimal places
n=round(val(n)*(10^k))
i=len(n)
if i<k+1
n+=string(k-i+1,"0") 'pad right
i+=k
endif
n=left(n,i-k)+"."+mid(n,i-k+1,k) 'insert decimal pt
endif
endif
endif
return n
end function
FUNCTION PBMAIN () AS LONG
local vsing as single = 3.141519
local vdoub as double = 3.141519
static vint as long
local vquad as quad = 4989895
local ws as wstring = "0"
local s as string = "$ 0,.00"
'vint += 1 ' i need to fix this.
LOCAL y AS long = 3.7
local z AS double = 12345.12321
incr vint
p? FORMAT$(0, ws)
p? FORMAT$(2323332.15, s)
p? FORMAT$(0, "0.000")
p? FORMAT$(2323332.15, "0.000")
p? str$(2323332.123)
p? str$(2323332)
p? str$(vint)
p? FORMAT$(0)
p? FORMAT$(1)
p? FORMAT$(vsing)
p? FORMAT$(vdoub)
p? FORMAT$(vint)
p? FORMAT$(vquad)
END FUNCTION
pbmain
wait
-
Hi Charles, this format implementation is a bit more complex, because it involves number customization beyond simple manipulations.
For example, it rounds the number at the specified number of decimals contained in the format string (if present), this gives a more precise rounding that rounding it at an arbitrary place (str(x) vs str(x, d)). . It adds thousands commas etc.
The format function works fine.
It is nice to know about the quad fix. Thanks!
-
Hi Brian,
I have added thousands-comma.
iif$ does not appear tointerfere with the format$ function. Macro functions always generate unique temp variables when invoked.
$filename "o.exe"
uses rtl64
uses console
def str$ str
def incr inc
def p? printl
function format$(string n, optional string f) as string
if f
int i=instr(f,".")
if i 'count places to right
int j=len(f)
int k=j-i
if k>0 'decimal places
n=round(val(n)*(10^k))
i=len(n)
if i<k+1
n+=string(k-i+1,"0") 'pad right
i+=k
endif
n=left(n,i-k)+"."+mid(n,i-k+1,k) 'insert decimal pt
endif
endif
endif
int i=instr(f,",")
if i 'comma thousands
int j=instr(n,".")
if j=0 then j=len(n)+1
if j>3
string m=n
for i=j-3 to 2 step -3
n=left(n,i-1)+","+mid(n,i) 'insert commas
next
endif
endif
return n
end function
macro iif$ string(R,X,A,B)
if X
R=A
else
R=B
endif
end macro
FUNCTION PBMAIN () AS LONG
local vsing as single = 3.141519
local vdoub as double = 3.141519
static vint as long
local vquad as quad = 4989895
local ws as wstring = "0"
local s as string = "$ 0,.00"
'printl iif$(1<0, "ok","nok")
int c1=1000000, c2=1000000
double t2n12=1.2345
int i
for i=1 to 8
PRINTl IIF$((c1=1000000) AND (c2=1000003), "*OK!* ", "ERROR ") &
" " & RTRIM(FORMAT$(t2n12, "0.00") )
c2++
next
'vint += 1 ' i need to fix this.
LOCAL y AS long = 3.7
local z AS double = 12345.12321
incr vint
p? FORMAT$(0, ws)
p? FORMAT$(2323332.15, s)
p? FORMAT$(0, "0.000")
p? FORMAT$(2323332.15, "0.000")
p? str$(2323332.123)
p? str$(2323332)
p? str$(vint)
p? FORMAT$(0)
p? FORMAT$(1)
p? FORMAT$(vsing)
p? FORMAT$(vdoub)
p? FORMAT$(vint)
p? FORMAT$(vquad)
END FUNCTION
pbmain
wait
-
Thanks Charles. I had to do mine the way i did it because of many factors... like compatibility. in PB i do this (weird example for explanation's sake):
stdout FORMAT$(12345678.2238, ",#,# # #.#")
And i get this:
,12,345,6 7 8.2
The function PluriBASIC generates for Oxygen outputs exactly the same.