Bugs

General discussion for topics related to the FreeBASIC project or its community.
Post Reply
Munair
Posts: 1286
Joined: Oct 19, 2017 15:00
Location: Netherlands
Contact:

Re: Bugs

Post by Munair »

fxm wrote: Feb 23, 2022 10:34 The same principle of tests (only at compile-time) are also applied to the initialization of all numeric variables (Byte, Short, Long, ...)
Yes, but as I already explained, the test should not apply to boolean because it doesn't have a range nor values that are used numerically that might affect the outcome of an arithmetic operation. In short, cbool(10) is not a critical conversion, so any warning here is pointless.

To wrap this up, I do not consider the compile-time warning a bug but rather a design issue.
Last edited by Munair on Feb 23, 2022 11:47, edited 1 time in total.
deltarho[1859]
Posts: 4308
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: Bugs

Post by deltarho[1859] »

Munair wrote:@deltarho:

#define IsTrue(x) iif(x <> 0, -1, 0)
#define IsFalse(x) iif(x <> 0, 0, -1)
I am unable to break that. :)

A little while ago, I was editing some code over and over again, but it kept failing. I tore everything up and walked away. A few days later, I returned and started from scratch. I solved the issue in minutes.

I started with a MrSwiss contribution, and we have been editing that. You, Munair, put MrSwiss' contribution to one side and started from scratch, coming up with a winner.

There is probably an idiom in some language to explain this method of problem-solving, but I cannot think of one in English.

Thank you.
Munair
Posts: 1286
Joined: Oct 19, 2017 15:00
Location: Netherlands
Contact:

Re: Bugs

Post by Munair »

You're welcome.

At times I experience the same; not being able to find a solution, sometimes for days. Often our mind is stuck thinking in one particular direction. By letting go and clearing the mind, a different approach and possibly a solution may surface.
fxm
Moderator
Posts: 12107
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Bugs

Post by fxm »

Indeed, this is not a bug because it seems to be intended.
It's more of a design choice that perhaps could be reconsidered.
dodicat
Posts: 7983
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Bugs

Post by dodicat »

There is something amiss with the str function IMHO (Since we are on a brand new BUGS thread)

Code: Select all


Dim As String g
Dim As double d=-1200.00676



Dim As Double t,t2
t=timer
For n As Long=1 To 1000000
      g=Str(-1200.00676) 'USE LITERAL
Next n
t=Timer-t
Print t,g
Print
t2=timer
For n As Long=1 To 1000000
      g=Str(d)           'USE VARIABLE
Next n
t2=timer-t2
Print t2,g
print
print "variable approx ";int(t2/t);" times slower than literal"
sleep 
other functions don't seem to have this difference, abs for instance.
fxm
Moderator
Posts: 12107
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Bugs

Post by fxm »

I think our "smart" compiler expresses directly 'Str(-1200.00676)' as '"-1200.00676"', as it does with many other expressions containing only literals or constants.
badidea
Posts: 2591
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: Bugs

Post by badidea »

Fixed :-)

Code: Select all

const As double d=-1200.00676
deltarho[1859]
Posts: 4308
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: Bugs

Post by deltarho[1859] »

@dodicat

How about this?

Code: Select all

FreeBASIC
 
 0.02316139341564849        -1200.00676
 
 0.654508045023249          -1200.00676
 
variable approx  28 times slower than literal
 
PowerBASIC
 
 0.403733714759837           -1200.00676
 
 0.403909644940907           -1200.00676
 
variable approx  1  times slower than literal
PowerBASIC is known for its string handling functions and its variable speed is faster than FreeBASIC. However, PowerBASIC's variable and literal speeds are almost identical.

FreeBASIC's literal speed is astonishing, but fxm has explained why that is.

@badidea

Fixed only if d is not a variable.

Added: Normally using gcc -O3 beats the pants off PowerBASIC but with string handling PowerBASIC is in a class of its own.
Last edited by deltarho[1859] on Feb 23, 2022 12:52, edited 1 time in total.
Munair
Posts: 1286
Joined: Oct 19, 2017 15:00
Location: Netherlands
Contact:

Re: Bugs

Post by Munair »

badidea wrote: Feb 23, 2022 12:21 Fixed :-)

Code: Select all

const As double d=-1200.00676
This is one of the reasons why I chose to interpret immediates / literals as constants when I began designing the SharpBASIC compiler (not finished yet :wink: ) For example, here:

Code: Select all

const d = -1200;

main do
  print(d);
  print(-1200);
end
the printed literal -1200 is considered identical to the constant d:

Code: Select all

; load d
movsx   eax, word [_C4]
call    _sb_print_int
; load immediate constant '-1200'
movsx   eax, word [_C4]
call    _sb_print_int
; ...
SECTION .rodata
; int16
_C4                 dw -1200
call    _sb_print_int
There really isn't any difference between immediates and constants in this respect.
dodicat
Posts: 7983
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Bugs

Post by dodicat »

Some of the other string functions, bin, hex, don't have this slowness with a variable.
Powerbasic seems to have a solution (deltarho)
Const seems to convert to literal (badidea), I think you can change a const (hack), but that is no answer.
I no longer download fb source, so I take fxm's answer as reasonable.
Munair, make sure your sharpbasic takes the powerbasic path on this one.
SARG
Posts: 1764
Joined: May 27, 2005 7:15
Location: FRANCE

Re: Bugs

Post by SARG »

fxm wrote: Feb 23, 2022 12:19 I think our "smart" compiler expresses directly 'Str(-1200.00676)' as '"-1200.00676"', as it does with many other expressions containing only literals or constants.
I confirm that.
The first loop : only a string is assigned to g.
The second : converting float to string then assignment to g.


Edit
@dodicat
With hex the first loop uses -1200 for calculating the hex string value then assignment to g
The second : rounding, converting to integer, calculating the hex string value then assignment to g
I'm pretty sure that variable way is slower.
Munair
Posts: 1286
Joined: Oct 19, 2017 15:00
Location: Netherlands
Contact:

Re: Bugs

Post by Munair »

dodicat wrote: Feb 23, 2022 13:11 Munair, make sure your sharpbasic takes the powerbasic path on this one.
I'll do my best, although I'm not at all familiar with PowerBasic. But I do know its history and the author's background.
Last edited by Munair on Feb 23, 2022 13:34, edited 1 time in total.
dodicat
Posts: 7983
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Bugs

Post by dodicat »

SARG
The hex,bin,oct are only 7/8 times slower.
If str was only 7/8 times slower it would be a great improvement.
deltarho[1859]
Posts: 4308
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: Bugs

Post by deltarho[1859] »

dodicat wrote:If str was only 7/8 times slower it would be a great improvement.
And probably an impossible one, since that would be over twice the speed of PowerBASIC.

Paul Squires wrote quite a few Ansi string handling functions for FreeBASIC because there was so few of them. Bob Zale, on the other hand, knocked out a pile of them. He even wrote a 'Stringbuilder object' which executed at lightning speed because he was not happy with the speed of the standard concatenation operators.
!Munair" wrote:I'll do my best, although I'm not at all familiar with PowerBasic.
PowerBASIC is not open source, so I doubt that we ever know how Bob mangaged to get his string handling functions to run so fast.
dodicat
Posts: 7983
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Bugs

Post by dodicat »

deltarho.
I know that bin, hex, . . . are completely different algorithms, str is quite involved.
jj2007's dll function written in masm basic by himself was, according to him, a few hundred lines long, but it is much faster than str.
(Maybe I'll get banished for saying this.)
All of the c++ float to string functions are also slow, some only giving a few decimal places.
Pascal's str is fast, but either gives out scientific notation, or you have to give the function a number of decimal places which is not possible to pre judge.
Post Reply