Liberty BASIC Community Forum
« val reacts on "." or "e" anythere »

Welcome Guest. Please Login or Register.
Nov 17th, 2017, 10:28pm


Rules|Home|Help|Search|Recent Posts|Notification

Problems installing Liberty BASIC? Read the Vista/Win7 Installation FAQ
Looking for a categorized List of Bug Reports? Visit the Liberty BASIC Bug Tracker

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: val reacts on "." or "e" anythere  (Read 96 times)
tsh73
Board Moderator

member is offline

Avatar

Anatoly (real name)


PM

Gender: Male
Posts: 1686
xx val reacts on "." or "e" anythere
« Thread started on: Mar 1st, 2017, 02:32am »

Problem:
VAL() reacts on "." or "e" anythere on source string, triggering result to be double.
Expected behavior: if number part is over, any amount of "e" or "." later on should not matter.

It just should not happen.

Code:
print val("3")
print val("3a")
print val("3e")
print val("3hghgfh e jkhkjh")   'e anythere in a string
print val("3hghgfh . jkhkjh")   '. anythere in a string
print val("123456789012345678901234567890")   'long number
print val("123456789012345678901234567890 abba gabba")   'long number followed by junk
print val("123456789012345678901234567890 abba gabba hey")   'long number followed by junk with "e" or "."
 


(I do not think it will affect many users anyway. If one needs number it's usually same thing getting 3 or 3.0.
But as last lines show, it could make some difference on long numbers.
)
« Last Edit: Mar 1st, 2017, 02:33am by tsh73 » User IP Logged

damned Dog in the Manger
tsh73
Board Moderator

member is offline

Avatar

Anatoly (real name)


PM

Gender: Male
Posts: 1686
xx Re: val reacts on "." or "e" anythere
« Reply #1 on: Mar 1st, 2017, 08:38am »

A bit more examples there it could break.
LB allows integer in IF condition, 0/not 0 style
But with real numbers it breaks (error in itself IMHO)
With this, you can unadvertedly get real number.

BUT once saved in a variable, it turns to normal integer value (no more problems)...

Code:
'0 is false
'not 0 is true

x = 1
if x then print "true" else print "false"
x = 0
if x then print "true" else print "false"

'now, check for number/not number

x=val("3 penny")
if x then print "true" else print "false"

'!! dies because one cannot use real number as a IF condition
'if val("3 penny") then print "true" else print "false"

'as well as
x=val("pennyless")
if x then print "true" else print "false"

'!! dies because one cannot use real number as a IF condition
'if val("pennyless") then print "true" else print "false"
 


« Last Edit: Mar 1st, 2017, 08:42am by tsh73 » User IP Logged

damned Dog in the Manger
Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Rules|Home|Help|Search|Recent Posts|Notification

Liberty BASIC Community Wiki
Wikispaces
Donate $6.99 for 50,000 Ad-Free Pageviews!

| |

This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls