» Home » VB Fibre
Site
News
Files

Visual Basic
Strings
Math
General
Properties
Memory
Methods

Search
Testing

Inline ASM-VB
Strings
Math
General
Memory

Search
Using inline ASM
Submit!

Int vs Fix

Hmm, not a real difference here. Both functions perform the same operation.

It seems that it does not really matter.

Code:
Public Function TestOne(ByRef A As Single) As Single '//Return as single TestOne = Int(A / 2.3) End Function Public Function TestTwo(ByRef A As Single) As Single '//Return as variant TestTwo = Fix(A / 2.3) End Function

Int % faster than Fix Int (sec) Fix (sec)
-6.4% 0.077279 0.082525
-7.6% 0.077504 0.083892
11% 0.084514 0.076169
6.2% 0.083238 0.078404
5.9% 0.082221 0.077606


User contributed notes:

Author: Alex Spurling (alex dot spurling (at) ntlworld dot com) Date: 21:04 13/04/2004
Look at your MSDN. They don't perform the same function. When using negative values, Int will round down the next lowest integer. Fix will round up to the next highest integer (ie truncate the decimals off).

Author: Jacob Roman () Date: 00:08 06/08/2004
I totally agree with Alex. I use Fix() on Bitshift operations on VB to get the exact results that C++ does. Int() throws the values off by 1 sometimes.

Author: Tom (hurendo_kun at hotmail dot com) Date: 04:09 23/09/2005
Probably not worth noting, but you've got an implicit type conversion there. Both Int and Fix take doubles, not singles.

I don't know what your "return as single/variant" comments are implying; they're both returning singles, and that takes another implicit conversion.

Add user-note
Author:
E-mail (optional):
Anti spam, please enter 'ok' without quotes:
Comment: