IonicWind Software

IWBasic => General Questions => Topic started by: Guilect on June 04, 2010, 12:20:40 PM

Title: question on OPT and floats
Post by: Guilect on June 04, 2010, 12:20:40 PM
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
Title: Re: question on OPT and floats
Post by: LarryMc on June 04, 2010, 01:27:48 PM
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
Title: Re: question on OPT and floats
Post by: sapero on June 04, 2010, 01:43:16 PM
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".
Title: Re: question on OPT and floats
Post by: Guilect on June 04, 2010, 04:05:14 PM
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.   ;)
Title: Re: question on OPT and floats
Post by: LarryMc on June 04, 2010, 04:42:05 PM
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
Title: Re: question on OPT and floats
Post by: sapero on June 19, 2010, 07:49:57 AM
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.