October 31, 2025, 03:06:59 PM

News:

IWBasic runs in Windows 11!


question on OPT and floats

Started by Guilect, June 04, 2010, 12:20:40 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Guilect

In the below piece of code, you can take turns uncommenting one of the "Sub test..." lines in turn and run the program as console.
You get different answers.

I thought I would always get the same answer (9).
And the same answer whether using floats or ints and the same answer
whether you are supplying all or some of the optional input parameters.
But the results are all over the place.
What am I missing?
sub test( a as int, opt b = 1 as int, opt c = 1 as int, opt d = 1 as int, opt e = 1 as int, opt f = 1 as int, opt g = 1 as int, opt h = 1 as int, opt i = 1 as int, opt j = 1 as int)
'sub test( a as float, opt b = 1 as float, opt c = 1 as float, opt d = 1 as float, opt e = 1 as float, opt f = 1 as float, opt g = 1 as float, opt h = 1 as float, opt i = 1 as float, opt j = 1 as float)
'sub test( a as float, opt b = 1.0 as float, opt c = 1 as float, opt d = 1 as float, opt e = 1 as float, opt f = 1 as float, opt g = 1 as float, opt h = 1 as float, opt i = 1 as float, opt j = 1 as float)
'sub test( a as float, opt b = 1.0 as float, opt c = 1.0 as float, opt d = 1.0 as float, opt e = 1.0 as float, opt f = 1.0 as float, opt g = 1.0 as float, opt h = 1.0 as float, opt i = 1.0 as float, opt j = 1.0 as float)

print a+b+c+d+e+f+g+h+i

ENDSUB

test(1)
test(1,1)
test(1,1,1)
test(1,1,1,1)
test(1,1,1,1,1)
test(1,1,1,1,1,1)
test(1,1,1,1,1,1,1)
test(1,1,1,1,1,1,1,1)
test(1,1,1,1,1,1,1,1,1)

waitcon

LarryMc

Don't know the specific answer to the shown problem.

Maybe this will tell you something: http://www.ionicwind.com/forums/index.php/topic,3459.msg27597.html#msg27597

Since floats are single precision I changed all the floats to doubles and get the right answers with the last sub (which sets defaults to 1.0 and not 1)

LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

sapero

This is a confirmed bug, the "as float" specifier is igored, just the type of your default value is used.
Change  "1 as float" to "1f as float".

Guilect

June 04, 2010, 04:05:14 PM #3 Last Edit: June 04, 2010, 04:22:59 PM by Guilect
Thanks guys.
This issue was causing me all kinds of grief.
I will use the work around.

Oh, and Larry,
the link you provided for me yields this :
"The topic or board you are looking for appears to be either missing or off limits to you."

I suspect it is the forum board of known bugs.
A lot of folks can not see this section of the forum.
Perhaps the new owner will allow members to see this.
I sure would like to know what issues exist so that I can work around them and
not bother posting the same ones again.   ;)

LarryMc

Quote from: Guilect on June 04, 2010, 04:05:14 PM
the link you provided for me yields this :
"The topic or board you are looking for appears to be either missing or off limits to you."

Sorry about that.  It was in a "Subscriber" area.

LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

sapero

sub work( opt a=1 as float )
print a
ENDSUB

work()

This is now correctly working in IWBasic v2. The value "1" is passed as float.