Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Having trouble understanding how to download FreeBasic.
#21
Thanks, Dr., I'll try it.
*****
Reply
#22
Quote:* Can I compile and get an executable using the IDE? Or will I have to run in emulation mode, which I don't want?

* By using the IDE, can I avoid MSDOS and the command-line alltogether?
Yes, the IDE will pass the bas file to fbc.exe for you, report any errors, and even run the program for you.

No emulation required: The IDE, fbc.exe, and the exes generated by fbc.exe will all be regular 32 bit Windows programs.

Yes, you can avoid MSDOS altogether, and you won't have to use any command prompt.
Reply
#23
STERLING, Thanks for the good info.

DR., I downloaded the IDE stuff you provided, ran the setup, and tested the little program (written by Neo) at the bottom of this post. It runs, but doesn't always give the right answers.
Examples:
Value of 9, base of 3, answer is 2 (correct)
Value of 27, base of 3, answer is 3 (correct)
Value of 125, base of 5, answer is -1 (error, should be 3, which it gives when run under DOS).

Is there any good reason for this? Is the program using something that is not supported by FB?
*****

Code:
rem Neo's Power-of solution

DECLARE FUNCTION GetExponent%(Value AS INTEGER, BaseValue AS INTEGER)

'/********************************************************************
'   Calculates and returns the integer exponent of BaseValue^x=Value,
'   if it exists, in which x is a positive integer number in I.
'   Value and BaseValue are required to be postive integer numbers
'   Returns -1 if the exponent doesn't exist
'   The parameters and return value all span I-positive < 32767
' ********************************************************************/

dim v as integer
dim b as integer

print "Enter the value";
input v
print "Enter the base";
input b

print GetExponent(v,b)

input x  'For running in FB to see the output.

system

END

FUNCTION GetExponent(Value AS INTEGER, BaseValue AS INTEGER)
   ' /*****************************************************
   '   Exclude some general mathematical exceptions to LOG
   '  *****************************************************/
   IF BaseValue = 1 AND Value <> 1 THEN
      GetExponent = -1: EXIT FUNCTION
   ELSEIF (BaseValue = 1 AND Value = 1) OR (BaseValue = 0 AND Value = 0) THEN
      GetExponent = 1: EXIT FUNCTION
   ELSEIF (Value = 0 AND BaseValue <> 0) THEN
      GetExponent = -1: EXIT FUNCTION
   END IF
   IF BaseValue < 1 OR Value < 0 THEN
      GetExponent = -1: EXIT FUNCTION
   END IF

   '/**********************************
   '   Calculate the exponent required
   ' **********************************/
   Exponent# = LOG(CDBL(Value)) / LOG(CDBL(BaseValue))

   '/**********************************************************
   '   See if it is an integer exponent and return it if it is
   ' **********************************************************/
   IF Exponent# = INT(Exponent#) THEN
      GetExponent = INT(Exponent#)
   ELSE
      GetExponent = -1
   END IF
END FUNCTION
Reply
#24
changed exponent# to exponent! and took out the cdbl's and it worked perfectly. doubles are evil for seeing if they're whole numbers, and they're more precision than you need anyway if all you're doing anyway since you only use the value if it's a whole number.
ttp://m0n573r.afraid.org/
Quote:quote: "<+whtiger> you... you don't know which way the earth spins?" ... see... stupidity leads to reverence, reverence to shakiness, shakiness to... the dark side
...phear
Reply
#25
or, here's a way to keep the double precisions.
Code:
FUNCTION GetExponent(Value AS INTEGER, BaseValue AS INTEGER)
   ' /*****************************************************
   '   Exclude some general mathematical exceptions to LOG
   '  *****************************************************/
   IF BaseValue = 1 AND Value <> 1 THEN
      GetExponent = -1: EXIT FUNCTION
   ELSEIF (BaseValue = 1 AND Value = 1) OR (BaseValue = 0 AND Value = 0) THEN
      GetExponent = 1: EXIT FUNCTION
   ELSEIF (Value = 0 AND BaseValue <> 0) THEN
      GetExponent = -1: EXIT FUNCTION
   END IF
   IF BaseValue < 1 OR Value < 0 THEN
      GetExponent = -1: EXIT FUNCTION
   END IF

   '/**********************************
   '   Calculate the exponent required
   ' **********************************/
   Exponent# = LOG(Value) / LOG(BaseValue)

   '/**********************************************************
   '   See if it is an integer exponent and return it if it is
   ' **********************************************************/
   IF int(BaseValue ^ INT(Exponent#)) = Value THEN
      GetExponent = INT(Exponent#)
   ELSE
      GetExponent = -1
   END IF
END FUNCTION
ttp://m0n573r.afraid.org/
Quote:quote: "<+whtiger> you... you don't know which way the earth spins?" ... see... stupidity leads to reverence, reverence to shakiness, shakiness to... the dark side
...phear
Reply
#26
Floating-point numbers should never be compared for equality, at least use an epsilon: http://teaching.idallen.com/cst8110/97s/...point.html .

FB will leave the floating-point operands in the FPU stack (80-bit precision) when possible, while in QB all functions returning floats had to store the results on vars (the hidden argument), where you have max 64 bits with DOUBLE's.
Reply
#27
Thanks, Dumbledore.

So what's the tip regarding using "double" in FB? Are you saying that it should not be used?
*****
Reply
#28
Where did you get that idea?

I said, comparing floating-point numbers for EQUALITY is not recommended in ANY language.
Reply
#29
V3czOr,

Ok, ok, I get your point. After thinking about it, you're right, comparing floating point numbers for equality is risky and should be avoided.

I originally thought that it was a FB incompatibility. In the case of this little program, the floating point problem did not manifest itself in Qbasic, but in FB it did.
Thanks.
*****
Reply
#30
Well, here I am 4 weeks later. With the great help from you guys, and your patience with me, I finally accomplished what I intended to do using FB, which is:
* Write a program in QB.
* Compile it at home with FB, and test it.
* Take it into work and install on a PC which does not allow MSDOS nor any 16 bit programs.
* EUREKA!!! The son-of-a-gun runs like a charm. :bounce:

The people at work thought I was crazy when I told them what I was gonna do. Now they're believers when they saw it run.

FB could start a revolution. All us old QB or QuickBasic programmers that were laughed at for using Basic and MSDOS, can now have the last laugh.

Thanks again to you guys.
*****
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)