Not a number is a number, problem

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Davidv
Posts: 77
Joined: Sun Apr 09, 2006 1:51 am
Location: Australia

Re: Not a number is a number, problem

Post by Davidv » Sun Jan 17, 2021 3:45 am

Hello people

Thank you for your several interesting replies, to some of which I will respond.

@Craig, as I suggested in my first two posts, I am unable to lose the string other than by persuading both the Australian Stock Exchange and a $2Bn medical company to change their name and ticker. Otherwise, rest assured I would.

@dunbarx, I have been vaguely aware that Transcript / Revolution / LiveCode did this "forever". I found a specific recent reference on this page:https://downloads.livecode.com/livecode ... 0_dp_1.pdf Search for "Nan"

@SparkOut, that looks a satisfactory solution thank you. It should not affect speed much (and that is not a critical factor), and is clean in appearance and meaning.

Yes, it looks to be a bug. Out of curiosity, I tried the 'strictly' operator on my test code, as follows. Note I use AND first time and OR the second.

Code: Select all

put "NAN,HTH,$42.70" into inLine
put "NAN" into aCode
get ((aCode is strictly a string) and ((item 1 of inLine) is strictly a string))
answer "Both strings?" && it
if item 1 of inLine < aCode then
   answer "NAN < NAN"
else
   if item 1 of inLine = aCode then
      answer "NAN = NAN"
   else 
      answer "NAN > NAN"
   end if
end if
get ((aCode is strictly an integer) or ((item 1 of inLine) is strictly an integer))
answer "Either an intteger?" && it
Yes, it looks like a bug, especially that it does not appear to be universal to all uses of the string "NAN".

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9567
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Not a number is a number, problem

Post by dunbarx » Sun Jan 17, 2021 5:17 pm

Hi

I am both "Craig" and "dunbarx". Dual personality, you know.

But once you have your imported data fully "inside" LC, can't you replace "NAN" with some other string ("NON", just so you can see it easily?), massage all your data as required, then restore the string "NAN" and lastly return that data to wherever?

Craig

SparkOut
Posts: 2834
Joined: Sun Sep 23, 2007 4:58 pm

Re: Not a number is a number, problem

Post by SparkOut » Sun Jan 17, 2021 8:48 pm

dunbarx wrote:
Sun Jan 17, 2021 5:17 pm
Hi

I am both "Craig" and "dunbarx". Dual personality, you know.

But once you have your imported data fully "inside" LC, can't you replace "NAN" with some other string ("NON", just so you can see it easily?), massage all your data as required, then restore the string "NAN" and lastly return that data to wherever?

Craig
No no NOOOOOOOOOO! Please!

Can't you just replace "width" with "wodth" or "false" with "folse" or "key" or "koy" or "anything that should be a literal string" with "onything thot shoold bo a lotorol strong"? Can't you just replace "string" with "strong"? oh, wait...

Forcing evaluation with value(item 1 of aLine) is a suitable kludge to deal with this specific case. But by all that's reasonable, this should be fixed and no data massaging should be necessary.
@David please can you raise a bug report for this?

Davidv
Posts: 77
Joined: Sun Apr 09, 2006 1:51 am
Location: Australia

Re: Not a number is a number, problem

Post by Davidv » Sun Jan 17, 2021 10:23 pm

Craig, ah, sorry, I did some handwritten notes and fiddled back and forth, so losing the association. I am convinced of your essential unity. :)

SparkOut, bug submitted, No 23063, with a simple illustrative stack.
https://quality.livecode.com/show_bug.cgi?id=23063

Davidv
Posts: 77
Joined: Sun Apr 09, 2006 1:51 am
Location: Australia

Re: Not a number is a number, problem

Post by Davidv » Sun Jan 17, 2021 10:31 pm

Regarding other workarounds, I had already considered adding an arbitrary character to both sides of every comparison. That was unattractive. Another was to use filter to extract the NAN line, knowing I would have the correct one without further comparison against the list. Comparing a simple variable with a field works. The fact that this problem occurs only when one (or both?) of the elements is a list item appears to be an essential component of the problem.

Anyway, thank you all for your assistance, both in elucidating the problem and finding a sufficient workaround for now.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9567
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Not a number is a number, problem

Post by dunbarx » Mon Jan 18, 2021 2:03 am

@ Sparkout.

I am not suggesting that we substitute "41" for "42". That would not be the correct answer to "6 x 9". I am suggesting, absent fixing the issue in the engine, which will not happen before tomorrow's Australian exchange opening, a workAround.

@David.

Glad you have a way forward.

Craig

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3975
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: Not a number is a number, problem

Post by bn » Mon Jan 18, 2021 2:28 am

Another way to force a string compare

note

Code: Select all

if item 1 of inLine begins with aCode and (length(item 1 of inline) = length(aCode)) then

Code: Select all

on mouseUp pMouseBtnNum
   put "NAN,HTH,$42.70" into inLine
   put "NAN" into aCode
   get ((aCode is strictly a string) and ((item 1 of inLine) is strictly a string))
   answer "Both strings?" && it
   if item 1 of inLine < aCode then
      answer "NAN < NAN"
   else
      if item 1 of inLine begins with aCode and (length(item 1 of inline) = length(aCode)) then
         answer "NAN = NAN"
      else
         answer "NAN > NAN"
      end if
   end if
   get ((aCode is strictly an integer) or ((item 1 of inLine) is strictly an integer))
   answer "Either an intteger?" && it
end mouseUp
Kind regards
Bernd

Bernard
Posts: 351
Joined: Sat Apr 08, 2006 10:14 pm
Location: London, England

Re: Not a number is a number, problem

Post by Bernard » Tue Mar 02, 2021 8:12 pm

Even weirder IMO is this.

Code: Select all

put NAN is a number
gives

Code: Select all

true
Assuming this mysterious NAN means "not a number" then surely when asked what type it is it should not be numeric?

Equally, this is weird.

Code: Select all

put NaN/0
gives

Code: Select all

nan
Meanwhile

Code: Select all

put "xero" is NaN
gives

Code: Select all

false
Surely some nonsense word delimited by quotation marks is certainly not a number. Yet NaN comparison says it is not-NaN.

After 20 years with LC, this is probably the weirdest anomaly I've ever seen. NaN comparison only returns true when NaN is tested as a number. Since it looks like it was introduced in 9.5 to deal with issues around the infinity constant, it certainly looks like it's a problematic implementation.

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Not a number is a number, problem

Post by bogs » Tue Mar 02, 2021 8:35 pm

Bernard wrote:
Tue Mar 02, 2021 8:12 pm
After 20 years with LC, this is probably the weirdest anomaly I've ever seen.
Well, I haven't gotten anywhere NEAR your years in, but I think I can match (or maybe top) that one, try this on for size :twisted:

I have a line in a field which consists of 1 tab and 4 spaces. I have other lines that consist of date items or integers. I want to know as I am checking each line if it is relatively empty (no numbers or letters) or if it has text, but no matter what I tested, I couldn't differentiate whether the line was blank or not, so I decided to check at the character level.

Code: Select all

put the text of the mouseLine into tLine

   repeat for each character x in tLine
 	put charToNum(x) & "," after tLine
	put tLine
   end repeat
For a line with a tab and 4 spaces, THIS is what I got back -

Code: Select all

	    9,32,230,11,0,
Gee golly, let's break that down!
1.) 9 TAB (horizontal tab)
2.) 32 SPACE
3.) 230 = not in a regular ascii table, that is for sure
4.) 11 VT (vertical tab) !?!?!
5.) 0 NUL (null)

I get why 1 and 2 are there, but why is a vertical tab in there ? Null character ?? 230 (whatever that is) ?!?

The lines with actual text characters and numbers were not to be denied either, bringing no less than 5 null characters, but at least I don't see any vertical tabs hee hee ! Of course, I *do* see some FF (NP form feed, new page) as well as CRs :shock:
Sun, Feb 28, 2021 83,117,126,13,16,80,12,9,0,116,124,13,0,0,21,4,12,1,4,2,0,0,
Image

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9250
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Not a number is a number, problem

Post by richmond62 » Tue Mar 02, 2021 8:40 pm

For anyone who is interested 00E6 (230) is a lower case ash: æ

https://www.unicode.org/charts/PDF/U0080.pdf

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Not a number is a number, problem

Post by bogs » Tue Mar 02, 2021 8:47 pm

Well I know for a fact I didn't put one of those into this :twisted:
Image

Davidv
Posts: 77
Joined: Sun Apr 09, 2006 1:51 am
Location: Australia

Re: Not a number is a number, problem

Post by Davidv » Tue Mar 02, 2021 10:12 pm

@Bernard: if you look at the stack I uploaded with the bug report, it shows that all of the following are true:
NAN = NAN
NAN > NAN
NAN is a number
NAN is [strictly] a string
I will leave that until the bug gets reviewed.

@bogs: Is there something about what is the mouseLine? I set up your code input thus:

Code: Select all

put tab & space && space into tLine
   repeat for each character x in tLine
   put charToNum(x) & "," after tLine
   put tLine
and got this:
9,32,32,32,
Which is the input line plus correct conversions [edit: except the forum display cuts off the leading tab and spaces]

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Not a number is a number, problem

Post by bogs » Tue Mar 02, 2021 10:37 pm

Davidv wrote:
Tue Mar 02, 2021 10:12 pm
@bogs: Is there something about what is the mouseLine?
Not sure what you mean? This is the line / field setup -

Image

For each line below the date, there will be times inserted by the script. I needed to find out which lines were occupied, and which weren't, One line in each date block is 'empty' except for a tab, however, I couldn't reliably find out whether they were actually empty or not. The results you see up there are from the mouse being over an empty (or tab / spaces) line, and lines with the time or date.

As examples, i load the date thus:

Code: Select all

  if (line 2 of field fldRecs is empty) or (line 2 of field fldRecs is not the abbreviated english date)  then 
      put cr & the abbreviated english date & cr & cr after line 1 of field fldRecs
   end if
The time and number are inserted like so:

Code: Select all

put the system time & tab & field "txtEntry" & cr into line theLine of field fldRecs
As you can see, I am certainly not putting any wierdness in there, but the mouseLine routine is sure telling me there is some :twisted:

Don't sweat it though, it is likely a bug in the version of the IDE I use, which is nothing like the new IDEs.
Image

Davidv
Posts: 77
Joined: Sun Apr 09, 2006 1:51 am
Location: Australia

Re: Not a number is a number, problem

Post by Davidv » Tue Mar 02, 2021 10:43 pm

OK, I won't sweat it. :D

AxWald
Posts: 578
Joined: Thu Mar 06, 2014 2:57 pm

Re: Not a number is a number, problem

Post by AxWald » Wed Mar 03, 2021 1:55 pm

Bogs,

changing a variable while looping through it - is it such good an idea?
I'd expect strange results :)

Have fun!
All code published by me here was created with Community Editions of LC (thus is GPLv3).
If you use it in closed source projects, or for the Apple AppStore, or with XCode
you'll violate some license terms - read your relevant EULAs & Licenses!

Post Reply

Return to “Talking LiveCode”