Author Topic: I've asked this before... but...  (Read 1848 times)

B+

  • Full Member
  • ***
  • Posts: 215
    • View Profile
Re: I've asked this before... but...
« Reply #30 on: May 13, 2015 »
Thanks for the info B+.  I am slowly figuring out the float thingy.  I have particular difficulty when both float and integer are combined in a calculation.  I apologise for not being as quick as others, when it comes to floating point, I have not had to deal with them in the past.  *sigh*

J

Hi J,

Who the heck can be quick with this crazy system? I was surprised about the number literals!
I was surprised by how much I have worked with Naalaa and didn't notice the thing with number literals. How many times have I been hung up because 1 was not written as 1.0? .113 not 0.113 and I thought something else was wrong! How many heads scratched and hairs pulled out for such minor things. How many more would be using Naalaa now, except for these unintuitive things?

Newbies need to be warned! I think I will change my signature.

B+
B+

B+

  • Full Member
  • ***
  • Posts: 215
    • View Profile
Re: I've asked this before... but...
« Reply #31 on: May 13, 2015 »
I am still working on Johnno's question about handling calculations, perhaps I just need more experience coding in Naalaa for stuff to fall into place, the reward is great, speed! The Tree2 thing I did recently, I can't imagine it running nearly so well in the my other Basic's, I should check.

There must be a bigger picture logic to this float issue, one doesn't develop a whole dialect and call it Naalaa to be obtuse.

It is true that integers run a whole lot faster in compilers, so keeping to them is a good idea.
It is generally true, except for the trig functions, that all the procedures and functions take integer arguments.

Think integers, I think is our motto here.

B+
B+

B+

  • Full Member
  • ***
  • Posts: 215
    • View Profile
Re: I've asked this before... but...
« Reply #32 on: May 13, 2015 »
Yep, SmallBASIC blows it's stack when I try to run Tree2 translation from Naalaa.
It is remotely possible (read: very likely) I messed up somewhere in the translation but I never had much luck with recursive processes in SmallBASIC.

B+
B+

B+

  • Full Member
  • ***
  • Posts: 215
    • View Profile
Re: I've asked this before... but...
« Reply #33 on: May 14, 2015 »
MORE about floats and integer calculations, it is important to start off on right foot.

In the examples that come with Naalaa download we get a warning:
Code: [Select]
rem ==================================================================
rem Language example : Type conversion.
rem
rem By Marcus Johansson.
rem ==================================================================

rem As coersion is the work of the devil, NaaLaa is extremely strong
rem typed. Integer, floating point and string expressions and
rem variables are completely separated from each other. All the
rem examples below would generate an error:
rem anInteger = 5.0
rem aFloat# = "1.32"
rem aString$ = 543
rem if 1 >= 2.0 then wln "Awesome!"
Integer, floating point and string expressions and
variables are completely separated from each other.

So it seems we have to keep our whole expression "pure" of what type we are setting a variable at, including the literal numbers 1 or 1.0 and so on...

Here is something interesting about division that actually has a pure float form and a pure integer form:
Code: [Select]
rem integer division test does dividing by an integer make the answer a float or considered float operation?
set window 0,0,700,700
for i=1 to 10
wln i,".0/3.0=",float(i)/3.0,"   ",i,".0/-3.0=",float(i)/-3.0
next
wln"press any..."
wait keydown

rem you can not write: wln i+"/3="+i/3 because + with string makes it a string operation

for i=1 to 10
wln i,"/3=",i/3,"    ",i,"/-3=",i/-3
rem OR
rem write i
rem write "/3="
rem wln i/3
next

wln "press any to end..."
wait keydown

« Last Edit: May 14, 2015 by B+ »
B+

B+

  • Full Member
  • ***
  • Posts: 215
    • View Profile
Re: I've asked this before... but...
« Reply #34 on: May 14, 2015 »
Code: [Select]
rem logic integer versus float test
if 1=1.0 then wln "1 an integer should not even be compared to 1.0 a float! What were you thinking!"
wln "end of test, press any..."
wait keydown
B+

Peter

  • Guest
Re: I've asked this before... but...
« Reply #35 on: May 14, 2015 »
Quote
What were you thinking!

float(1) = 1.0

B+

  • Full Member
  • ***
  • Posts: 215
    • View Profile
Re: I've asked this before... but...
« Reply #36 on: May 14, 2015 »
1=int(1.0) and 1=int("1")

wait... how about...
B+

johnno56

  • Guest
Re: I've asked this before... but...
« Reply #37 on: May 14, 2015 »
Without testing, I thought that the 'int()' command is related to numbers, but not necessarily strings. If it were me, I would have used int(val("1")). But that's me... and what do I know? *sigh*

J