Int & Fix Functions

R

RN1

The book I am referring to learn ASP states the following about the
Int & Fix VBScript Maths functions:

=========================================
Both Int & Fix return the integer portion of the number but the
difference lies in handling negative numbers. Int returns the first
integer lesser than or equal to the number whereas Fix returns the
first integer greater than or equal to the number.
=========================================

I guess using the term "integer portion" would have been more
appropriate than the term "first integer", isn't it?

Nevertheless, isn't the difference stated above wrong to some extent?
This is because the output of passing a negative number to the Int
function (assuming that the number is a decimal/floating point number
& that all the integers after the decimal point are not 0) will ALWAYS
be LESSER than the integer portion of the negative number; the output
will NEVER be EQUAL to the negative number. For e.g. both

Int(-61.0003)

&

Int(-61.9999)

will return -62 which is LESSER than the integer portion of both
-61.0003 & -61.9999; it won't return -61 which is EQUAL to the integer
portion of both the negative numbers -61.0003 & -61.9999. Of course

Int(-61.0000)

&

Int(-61)

will return -61.

Also the output of passing a negative number to the Fix function (be
it a decimal/floating point number or a whole number) will ALWAYS be
EQUAL to the integer portion of the negative number; its output will
NEVER be GREATER than the integer portion of the negative number. For
e.g.

Fix(-61.0003)

Fix(-61.9999)

Fix(-61.0000)

&

Fix(-61)

will return -61 which is EQUAL to the integer portion of the 4
negative numbers; it won't return -60 which is GREATER than the
integer portion of the 4 negative numbers.

Please correct me if I am wrong.

Thanks,

Ron
 
E

Evertjan.

RN1 wrote on 22 dec 2007 in microsoft.public.inetserver.asp.general:
The book I am referring to learn ASP states the following about the
Int & Fix VBScript Maths functions:

=========================================
Both Int & Fix return the integer portion of the number but the
difference lies in handling negative numbers. Int returns the first
integer lesser than or equal to the number whereas Fix returns the

Must be a badly written book.

Methinks "less than" would do:

"5.2 being less than the integer 6, is even lesser than 5.3" ????????

first integer greater than or equal to the number.
=========================================

I guess using the term "integer portion" would have been more
appropriate than the term "first integer", isn't it?

No, "integer portion", though it gives a nice feeling, is only logical if
the numeric value is described as a string.

Any non integer real number has a "first integer" on "both sides" of it's
value.

MS-scripting reference 5.6 says:

"The difference between Int and Fix is that if number is negative, Int
returns the first negative integer less than or equal to number, whereas
Fix returns the first negative integer greater than or equal to number. For
example, Int converts -8.4 to -9, and Fix converts -8.4 to -8."

========================================
So int() returns the first integer value "less than",

while fix() returns the firrst integer value "nearer to zero".
========================================
Nevertheless, isn't the difference stated above wrong to some extent?
This is because the output of passing a negative number to the Int
function (assuming that the number is a decimal/floating point number

A "decimal number" in my book is just a way [11]
of writing a number to a string,
as it could also be a written as an octal [13]
or hexadecimal
or binary number [111],
or written "exponentially" [1.1e1] [.11e2]
or "scientific" [11e0] .

Yes, I know that a non integer number, when written decimaly, has numbers
right of the integer/fractional devision sign which are wrongly called
decimal figures.

A "floating point number" is a way of internally storing a number with
a mantissa and an exponent.

An integer can be, and with ASP-VBS is, stored as a floating point number!!

So let us say "non integer number".
& that all the integers after the decimal point

"integers after a decimal point"?
Do you mean "single figures" after ...
A integer being a numeric value.
are not 0) will ALWAYS

0) ????
be LESSER than the integer portion of the negative number; the output

.... always be LESS than ...
will NEVER be EQUAL to the negative number.

Why not?

Int(-61) is just -61
r e.g. both

Int(-61.0003)

&

Int(-61.9999)

will return -62 which is LESSER than the integer portion of both
-61.0003 & -61.9999;
LESS

it won't return -61 which is EQUAL to the integer
portion of both the negative numbers -61.0003 & -61.9999. Of course

So do not use this silly notion of "integer portion"

Int(-61.0000)

&

Int(-61)

will return -61.

Not exactly! Only in effext.

Do not mingle a numberic value as used by the computer,
with the way it is written as a litteral string in a source code.

===

What does the interpreting code with:

result = Int(-61.0000)

It first takes the litteral string -61.0000 and converts it to -61 and
[with asp-vbscript] stores that as a binary floating point coded value

Then the int() is applies to that value of -61,
returning -61.

===

What does the interpreting code with:

result = Int(-61)

It first takes the litteral string -61 and converts it to -61 and [with
asp-vbscript] stores that as a binary floating point coded value

Then the int() is applies to that value of -61,
returning -61.

===

Then this result in both cases is applied to a variable called "result" and
stored again coded as a binary floating point.

Also the output of passing a negative number to the Fix function (be
it a decimal/floating point number or a whole number) will ALWAYS be
EQUAL to the integer portion of the negative number; its output will
NEVER be GREATER than the integer portion of the negative number. For
e.g.

Fix(-61.0003)

Fix(-61.9999)

Fix(-61.0000)

&

Fix(-61)

will return -61 which is EQUAL to the integer portion of the 4
negative numbers; it won't return -60 which is GREATER than the
integer portion of the 4 negative numbers.

Please correct me if I am wrong.

Dear Ron, never, never again mix number values and the way they are stored
internally, with the way they are written as a string litteral [and only
then depend on the number base].

To show you that input and output string litterals
are not per definition so simple, try:

<%
Response.write fix(-int(6e3) + .5) & "<br>"
Response.write hex(-int(6e3))
%>

Can you deduct with reasoning what the outup will be?

[answer below]










































-5999
FFFFE890
 
E

Evertjan.

Dave Anderson wrote on 22 dec 2007 in
microsoft.public.inetserver.asp.general:
"Evertjan." "wrote":

You left off equality.

Add: "if not integer already" to both.
A "decimal number" in my book is just a way [11]
of writing a number to a string,
as it could also be a written as an octal [13]
or hexadecimal
or binary number [111],
or written "exponentially" [1.1e1] [.11e2]
or "scientific" [11e0] .


Those last two are decimal examples.


Yes.

How would you call this: 3.256
fractional?
 
E

Evertjan.

Dave Anderson wrote on 22 dec 2007 in
microsoft.public.inetserver.asp.general:
Rational, representing 3256/1000.

No, we were talking about ways to display numbers.

Rational numbers are a mathematic collection.
Of course, in many countries, that is just 3256, right?

Sorry?
 
E

Evertjan.

Dave Anderson wrote on 24 dec 2007 in
microsoft.public.inetserver.asp.general:
You asked what I would call it. It's not my problem if you don't like my
answer.

What is this with you, this is not a personal venetta?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top