Author Topic: float variables: use the "f" or not use the "f"  (Read 397 times)

Legacy_Terrorble

  • Sr. Member
  • ****
  • Posts: 370
  • Karma: +0/-0
float variables: use the "f" or not use the "f"
« on: February 09, 2014, 06:16:00 am »


                I thought I better get this clarified.

When I call a function, say DestroyObject(oItem,12.0f);  <-- see the "f"

What's the effect of using the "f" on the end of a float versus not using it in NWN script?

I've seen elsewhere that adding an F limits the size of the number... or something like that.

Gee, I'm really exposing my lack of homework on the matter, but your help is always appreciated.
               
               

               
            

Legacy_The Amethyst Dragon

  • Hero Member
  • *****
  • Posts: 2981
  • Karma: +0/-0
float variables: use the "f" or not use the "f"
« Reply #1 on: February 09, 2014, 08:50:38 am »


               I've never really understood it, either.  I never use it.
               
               

               
            

Legacy_Proleric

  • Hero Member
  • *****
  • Posts: 1750
  • Karma: +0/-0
float variables: use the "f" or not use the "f"
« Reply #2 on: February 09, 2014, 09:52:32 am »


               I no longer use it, either.
               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
float variables: use the "f" or not use the "f"
« Reply #3 on: February 09, 2014, 09:57:26 am »


               I dont think there is any different functionality. I use the faster that is without f.:innocent:

Easy to check imo:

compile a script once with a f and once without, then compare the compiled code (*,ncs) between each other in comparer.
               
               

               


                     Modifié par ShaDoOoW, 09 février 2014 - 09:57 .
                     
                  


            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
float variables: use the "f" or not use the "f"
« Reply #4 on: February 09, 2014, 02:03:14 pm »


               Have you ever gone from one programming language to another and found that you get a bunch of syntax errors just because you are typing code in the old form.   Or converted one language to another  .
 
The 'f'  at the end of the float was required in many assemblers/languages.  It was left in as optional in many assemblers just for just that reason.   It allowed programmers to go from a language that required the 'f' at the end of the float and still write the data type the same way in the current language even though it was not required.    

I can remember papers that even suggested that it was best practice to always use the 'f'.  It  basically  just boils down to convention though.  use it if you want to don't use it if you don't.  IF you flip back and forth with a language that requires it, you may find it easier to always use it, Then to try and remember when you have to use it.
               
               

               


                     Modifié par Lightfoot8, 09 février 2014 - 02:05 .
                     
                  


            

Legacy_leo_x

  • Sr. Member
  • ****
  • Posts: 403
  • Karma: +0/-0
float variables: use the "f" or not use the "f"
« Reply #5 on: February 09, 2014, 07:19:32 pm »


               I think in this case the guys at Bioware probably cribbed from a C/C++ language lexer/parser, which uses 'f' to distinguish float literals from double literals.  Since NWScript has no doubles, there probably is no difference one way or the other when compiled.
               
               

               


                     Modifié par pope_leo, 09 février 2014 - 07:23 .
                     
                  


            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
float variables: use the "f" or not use the "f"
« Reply #6 on: February 09, 2014, 08:56:23 pm »


               

pope_leo wrote...

I think in this case the guys at Bioware probably cribbed from a C/C++ language lexer/parser, which uses 'f' to distinguish float literals from double literals.  Since NWScript has no doubles, there probably is no difference one way or the other when compiled.


Yes that is mostlikely the case.  but even in C++  the f is optional.   It is the default case when no letter follows the number.   If you wanted to force the 80 bit float,  the  then the 'l' would be required to follow It.   Since it is not the default case. 
               
               

               
            

Legacy_Tarot Redhand

  • Hero Member
  • *****
  • Posts: 4165
  • Karma: +0/-0
float variables: use the "f" or not use the "f"
« Reply #7 on: February 09, 2014, 11:30:47 pm »


               My understanding is that it is there to help the compiler in the case where you want to assign a literal value with no fractional part to a float variable (eg MyFloat = 1f). As such it is redundant as you are unlikely to receive a syntax error if you omit the f.

TR
               
               

               
            

Legacy_Terrorble

  • Sr. Member
  • ****
  • Posts: 370
  • Karma: +0/-0
float variables: use the "f" or not use the "f"
« Reply #8 on: February 10, 2014, 04:38:19 am »


               Glad to hear it is of nominal importance, since I thought it looked nice one day and used it and can't remember where.

Thanks, everyone.