By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,320 Members | 2,212 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,320 IT Pros & Developers. It's quick & easy.

Int & Fix Functions

P: n/a
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
Dec 22 '07 #1
Share this Question
Share on Google+
8 Replies


P: n/a
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 [b]
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

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Dec 22 '07 #2

P: n/a
"Evertjan." "wrote":
========================================
So int() returns the first integer value "less than",

while fix() returns the firrst integer value "nearer to zero".
========================================
You left off equality.

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 [b]
or binary number [111],
or written "exponentially" [1.1e1] [.11e2]
or "scientific" [11e0] .
Those last two are decimal examples.

--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms.

Dec 22 '07 #3

P: n/a
Dave Anderson wrote on 22 dec 2007 in
microsoft.public.inetserver.asp.general:
"Evertjan." "wrote":
>========================================
So int() returns the first integer value "less than",

while fix() returns the first integer value "nearer to zero".
========================================

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 [b]
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?
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Dec 22 '07 #4

P: n/a
"Evertjan." wrote:
How would you call this: 3.256
fractional?
Rational, representing 3256/1000.

Of course, in many countries, that is just 3256, right?
--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms.

Dec 22 '07 #5

P: n/a
Dave Anderson wrote on 22 dec 2007 in
microsoft.public.inetserver.asp.general:
"Evertjan." wrote:
>How would you call this: 3.256
fractional?

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?

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Dec 22 '07 #6

P: n/a
"Evertjan." wrote:
>>How would you call this: 3.256
fractional?

Rational, representing 3256/1000.

No, we were talking about ways to display numbers.
Don't be obtuse.
Rational numbers are a mathematic collection.
You asked what I would call it. It's not my problem if you don't like my
answer.
>Of course, in many countries, that is just 3256, right?

Sorry?
No need to apoligize for regional differences in numeric representation.
"3.256" in one country is "3,256" in others. You have no control over that.

--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms.

Dec 24 '07 #7

P: n/a
Dave Anderson wrote on 24 dec 2007 in
microsoft.public.inetserver.asp.general:
>Rational numbers are a mathematic collection.

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?

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Dec 24 '07 #8

P: n/a
"Evertjan." "wrote":
>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?
It is not.

--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms.

Dec 25 '07 #9

This discussion thread is closed

Replies have been disabled for this discussion.