Author Topic: Is this a bug?  (Read 4883 times)

0 Members and 1 Guest are viewing this topic.

Nicola

  • Guest
Re: Is this a bug?
« Reply #30 on: September 11, 2020, 12:44:31 AM »
@Charles
Input is to be excluded. I tried as you suggested, the problem remains.

What is the difference in o2 progress?

Charles Pegge

  • Guest
Re: Is this a bug?
« Reply #31 on: September 11, 2020, 01:23:20 AM »
Thanks Nicola, that excludes Input().

Something in your 'Windows 10 Enterprise' system alters the behaviour of the compiler. Could you try fiddling with the printl statement:

    print "a       = " a cr
    print "a       = " str(a) cr
    etc.

OxygenBasicProgress is the most recent release

JRS

  • Guest
Re: Is this a bug?
« Reply #32 on: September 11, 2020, 01:24:47 AM »
I liked clicking on the Wizard and getting the latest release. A bit confusing what to grab on Github.

Charles,

I have Windows 10 Pro if you would like me to give that a try.

Nicola

  • Guest
Re: Is this a bug?
« Reply #33 on: September 11, 2020, 03:07:50 AM »
@Charles
Well, I solved everything with this change:

Code: [Select]
dim a, b as string
... But, strange to say, if I do
Code: [Select]
if a = "0" then exit do   
it doesn't work. Why?

Charles Pegge

  • Guest
Re: Is this a bug?
« Reply #34 on: September 11, 2020, 03:43:20 AM »
Thanks Nicola,

This is a string comparison: if a="" then exit do.
We also have a boolean null and empty string interpretation if not a then exit do'

But I still wonder whether str(a) works with a as double.



Yes John, a test on your system would be very useful.

About 6 rounds
Code: [Select]
    include "$/inc/console.inc"
     
    dim a,b as double
    global r as int
    sub _print()
    ====================================
            if r=1 then
                    printl "YES is an exact root"
            else
                    printl "NO it is not an exact root"
            end if
            printl
            r=0
    end sub
     
     
    '====== MAIN ===============
    do
     
    r=0
    printl "input a number: "
    'a=input()
    a = ltrim rtrim Input ' per togliere caratteri da input tipo CR
    if a=0 then exit do
cls
    b = sqrt(a)
    print "a       = " a cr
    print "SQRT(a) = " b cr
     
    printl "Text if the result = INT(result)"
    if b=int(b) then
             r=1
    end if
    _print
     
    printl "Text if the FRAC(result) has a fractional component"
    if frac(b)=0 then
            r=1
    end if
    _print
     
    printl "Text if result = TRUNC(result)"
    if b=trunc(b) then
            r=1
    end if
    _print
     
    printl "Test if Result - INT(result) = 0"
    if b - int(b) = 0 then
            r=1
    end if
    _print
     
    printl "Test if INT(Result)^2 = number in input"
    if int(b)*int(b) = a then
            r=1
    end if
    _print
     
    loop

JRS

  • Guest
Re: Is this a bug?
« Reply #35 on: September 11, 2020, 04:51:27 AM »
Here is the results on my Windows 10 Pro laptop. (up to date)

Code: [Select]
a       = 25
SQRT(a) = 5

Text if the result = INT(result)
NO it is not an exact root

Text if the FRAC(result) has a fractional component
YES is an exact root

Text if result = TRUNC(result)
YES is an exact root

Test if Result - INT(result) = 0
YES is an exact root

Test if INT(Result)^2 = number in input
YES is an exact root

--------------------------------------------------
a       = 63
SQRT(a) = 7.9372539331937721

Text if the result = INT(result)
NO it is not an exact root

Text if the FRAC(result) has a fractional component
NO it is not an exact root

Text if result = TRUNC(result)
NO it is not an exact root

Test if Result - INT(result) = 0
NO it is not an exact root

Test if INT(Result)^2 = number in input
YES is an exact root

--------------------------------------------------
a       = 33
SQRT(a) = 5.7445626465380286

Text if the result = INT(result)
NO it is not an exact root

Text if the FRAC(result) has a fractional component
NO it is not an exact root

Text if result = TRUNC(result)
NO it is not an exact root

Test if Result - INT(result) = 0
NO it is not an exact root

Test if INT(Result)^2 = number in input
NO it is not an exact root

--------------------------------------------------
a       = 50
SQRT(a) = 7.0710678118654755

Text if the result = INT(result)
NO it is not an exact root

Text if the FRAC(result) has a fractional component
NO it is not an exact root

Text if result = TRUNC(result)
NO it is not an exact root

Test if Result - INT(result) = 0
NO it is not an exact root

Test if INT(Result)^2 = number in input
NO it is not an exact root

--------------------------------------------------
a       = 128
SQRT(a) = 11.313708498984761

Text if the result = INT(result)
NO it is not an exact root

Text if the FRAC(result) has a fractional component
NO it is not an exact root

Text if result = TRUNC(result)
NO it is not an exact root

Test if Result - INT(result) = 0
NO it is not an exact root

Test if INT(Result)^2 = number in input
NO it is not an exact root

--------------------------------------------------
a       = 3
SQRT(a) = 1.7320508075688772

Text if the result = INT(result)
NO it is not an exact root

Text if the FRAC(result) has a fractional component
NO it is not an exact root

Text if result = TRUNC(result)
NO it is not an exact root

Test if Result - INT(result) = 0
NO it is not an exact root

Test if INT(Result)^2 = number in input
YES is an exact root

Note: Works from the IDE and as an .exe.

Nicola

  • Guest
Re: Is this a bug?
« Reply #36 on: September 11, 2020, 04:57:27 AM »
Thanks Charles.
Anyway, I was thinking, that if A is a string and I insert 0 (zero) in the INPUT, the condition
IF A = ​​"0"
must be true, otherwise there is a problem. Do not you agree?

The solutions you mentioned are good, but they should not rule out the possibility of taking the test I indicated.

-- Could it be possible that my version of Window will output a compile that produces this error?

Charles Pegge

  • Guest
Re: Is this a bug?
« Reply #37 on: September 11, 2020, 05:40:59 AM »
Yes, I was thinking of empty inputs.

A test to see what is going on with string a:

After cls
Code: [Select]
int i
for i=1 to len(a)
  print  ">>" i tab asc(a,i) cr
next


Nicola

  • Guest
Re: Is this a bug?
« Reply #38 on: September 11, 2020, 06:29:20 AM »
Something actually happens after sixth input, or turn. I have attached the results. The test_1 matches the results by inserting the control of every single asci, and strangely also the print a is always ok. The test_2 is without the check you indicated, and again the strange characters come out.


Charles Pegge

  • Guest
Re: Is this a bug?
« Reply #39 on: September 11, 2020, 07:20:25 AM »
Thanks Nicola,
Could you try running test_1 again but this time remove ltrim rtrim, so 'a' gets the whole input string. What happens on the 6th round is really curious.

Nicola

  • Guest
Re: Is this a bug?
« Reply #40 on: September 11, 2020, 08:32:01 AM »
the test I did was already without ltrim rtrim
 :)

Charles Pegge

  • Guest
Re: Is this a bug?
« Reply #41 on: September 11, 2020, 09:55:56 AM »
Can we find out what your console mode is:

Code: [Select]
int i
GetConsoleMode(ConsIn,i)
print "Cons input mode: " hex (i) cr
    print "a       = " a cr
    print "SQRT(a) = " b cr

mine is 1B7

If yours is different then you could try setting it before the do block
Code: [Select]
SetConsoleMode(ConsIn,0x1B7)

« Last Edit: September 11, 2020, 01:52:07 PM by Charles Pegge »

JRS

  • Guest
Re: Is this a bug?
« Reply #42 on: September 11, 2020, 11:11:53 AM »
Any chance you have WSL (Windows Subsystem for Linux) installed?

Quote
Under Microsoft Windows [Version 10.0.15063], attempting to use the WriteConsoleW low-level API to output to the console results in no text being printed under WSL.
« Last Edit: September 11, 2020, 05:09:19 PM by John »

Nicola

  • Guest
Re: Is this a bug?
« Reply #43 on: September 12, 2020, 07:45:59 AM »
Hi Charles.
First of all I wanted to tell you that these commands on the console are interesting.
I did the test by inserting the changes (the program is attached).
Nothing has changed. Although, I repeat, running the for ... next to see the asci the strange characters do not come out ...
Hello

Charles Pegge

  • Guest
Re: Is this a bug?
« Reply #44 on: September 12, 2020, 12:18:28 PM »
Nicola,

At last! This line causes the problem:

Code: [Select]
if b=int(b) then r=1 : end if

int(n) is currently not legit syntax
int is only to be used as a type.

The next release of o2 will catch this error.
« Last Edit: September 12, 2020, 01:19:09 PM by Charles Pegge »