[Gambas-user] Math bugs??

Fabien Bodard abidoo.too at ...11...
Mon Jun 14 20:30:07 CEST 2004


Le lundi 14 Juin 2004 19:31, Brant Wells a écrit :
>  Hey Nelson:
>
>  What should the value of 1\3 be?  For every operation that I have done
> where 1/3 < 1, or  1\3 <1 then I receive 0 (zero) for my answer.  A FLOAT
> number is not returned...  ie: 6/3 = 2...  and 6\3 = 2... but 1/3 = 0, and
> 1\3 = 0, when really 1/3 should =0.333~


>  Using Fabien's trick (ie: adding the .0 to the end of my integer) works
> fine for 1/3.0, but 1\3.0 returns an error message [Wanted integer, got
> float instead] (after looking at the help file, I realize that this error
> is expected...)
>
>  I was just shocked to find that when I did a
>
>  dim myVar as Float
  myvar=1/3.0

In other case send me an exemple.. i'll correct it !

Fabien

>   
>  myVar always came out to be zero, no matter if I used the format function
> or what.  It would be nice if the division would return  float value
> automagically if the number came out to be a fraction...  I guess I'm just
> still getting used to the Gambas syntax for stuff...  Thanks for helping me
> out, y'all!
>
>  ~Brant
>
>
>  Nelson Ferraz wrote:
>  [snip...]
>
> This trick can be useful in many arithmetic operations, but should be
> disabled when the expression involves a float division. That's why we have
> the backslash division (1\3).
>
>  "Premature optimisation is the root of all evil in programming".
>
>
> [snip....]


Number + Number 
		Adds two numbers. 
- Number 
		Computes the opposite sign of a number. Zero is the opposite of itself.
		N = 5
		R = -8
		PRINT N;" ! ";R; " , "; -N ; " !! "; -R 
		==> 5 ! -8 , -5 !! 8
Number - Number 
		Subtracts two numbers. 
Number * Number 
		Multiplies two numbers. 
Number / Number 
		Divides two numbers. A division by zero error will occur if the value of the
		number to the right of the slash is zero. 
Number ^ Power 
		Raises Number to the power Power . 
		PRINT 4^3 
		==> 48
Number \ Number                                    <========== here
		Computes the quotient of the two numbers. A division by zero error will
		occur if the value of the number to the right of the backslash is zero. A \
		B is the equivalent of INT(A/B).
		PRINT 9\4; " , "; 9 MOD 4 
		==> 2 , 1
Number AND Number 
		Computes the mathematical and of the binary value of the two numbers. 
		PRINT 5 AND 3
		==> 1 
Number MOD Number 
		Computes the remainder of the quotient of the two numbers. A division by
		zero error will occur if the value of the number to the right of the
		operator MOD is zero.
PRINT 9\4; " , "; 9 MOD 4 
		==> 2 , 1
Number OR Number 
		Computes the mathematical or of the binary value of the two numbers. 
		PRINT 5 OR 3
		==> 7 
Number XOR Number 
		Computes the mathematical exclusive or of the binary value of the two
		numbers. 
		PRINT 5 XOR 3
		==> 6 



  ------------------------------------------------------- This SF.Net email
> is sponsored by the new InstallShield X. From Windows to Linux, servers to
> mobile, InstallShield X is the one installation-authoring solution that
> does it all. Learn more and evaluate today!
> http://www.installshield.com/Dev2Dev/0504
> _______________________________________________ Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user




More information about the User mailing list