473,405 Members | 2,334 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Integer Division Broken?

Ben
Hi, I have an interesting example from my debugger. I have 2 variables:
sourcewidthnet and targetwidthnet. Notice the results in the debugger.
I'm going to be forced to use the int function of the decimal.toint32
since the \ operator doesn't appear to work, or I greatly misunderstand
the documentation on the \ operator.

decimal.Remainder(sourcewidthnet, targetwidthnet) 0.375D
sourcewidthnet 96D
targetwidthnet 2.125D
SourceWidthNet / TargetWidthNet
45.176470588235294117647058824D(SourceWidthNet \ TargetWidthNet)
48 Long
decimal.ToInt32((SourceWidthNet / TargetWidthNet)) 45 Integer

I can't justify the: 96 \ 2.125 = 48 answer at all!

Thanks for your input.

Nov 21 '05 #1
2 1634
It is correct. 96 \ 2 = 48. When you do an integer division, the divisor
is the integer part, which in this case is 2.

"Ben" <be***********@bankscorporation.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
Hi, I have an interesting example from my debugger. I have 2 variables:
sourcewidthnet and targetwidthnet. Notice the results in the debugger.
I'm going to be forced to use the int function of the decimal.toint32
since the \ operator doesn't appear to work, or I greatly misunderstand
the documentation on the \ operator.

decimal.Remainder(sourcewidthnet, targetwidthnet) 0.375D
sourcewidthnet 96D
targetwidthnet 2.125D
SourceWidthNet / TargetWidthNet
45.176470588235294117647058824D(SourceWidthNet \ TargetWidthNet)
48 Long
decimal.ToInt32((SourceWidthNet / TargetWidthNet)) 45 Integer

I can't justify the: 96 \ 2.125 = 48 answer at all!

Thanks for your input.

Nov 21 '05 #2
Ben
Ok, I finally see the documentation in the remarks section:

Remarks
Before division is performed, any floating-point numeric expressions
are coerced to Long if Option Strict is Off. If Option Strict is On, a
compiler error results

Silly me, thanks.

Still to get what I'm looking for the int() and decimal.tointxx
routines will work, thanks again.

Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Tim Rowe | last post by:
If I do from __future__ import division then eval(1/2) gives me 0.5 as expected. But if I do print input("enter a sum: ") and enter 1/2 as the sum I get 0 as if I hadn't done the import. I thought...
24
by: Teis Draiby | last post by:
In .NET, can I be sure that the result of a division between two integers always is truncated rather that rounded to nearest? Example: 99 / 50 = 1 regards, Teis
3
by: Mark McConnell | last post by:
Regarding deserializing XML into a custom object... I've been able to deserialize an XML doc into my custom object and everything works great. The problem I am encountering is when one of the...
20
by: GS | last post by:
The stdint.h header definition mentions five integer categories, 1) exact width, eg., int32_t 2) at least as wide as, eg., int_least32_t 3) as fast as possible but at least as wide as, eg.,...
3
by: Janice | last post by:
I got this question from my textbook and I cannot understand the theory. When a signed positive integer X divided by pow(2,k), the result is shifting k bits to right and putting w-k bits of 0 from...
10
by: Mike S | last post by:
Does anyone know the logic behind why in VB.NET the result of a floating-point division ('/') is -rounded- on being converted to an integer type, such as with statements like Dim x As Integer =...
8
by: Candace | last post by:
I am using the following code to pick off each digit of a number, from right to left. The number I am working with is 84357. So for the first iteration it should return the number 7 and for the...
5
by: bdsatish | last post by:
How does (a/b) work when both 'a' and 'b' are pure integers ? 4 -5 Why is it -5 ? I expect it to be -4 ? Because, in C/C++, 9/2 is 4 and so negative of it, (-9/2) is -4. What should I do...
14
by: Default User | last post by:
Hi, If I have three 64 bit integers and I want to do this operation on them: x*y/z Lets say that what we are multiplying by (y) is offset by what we are dividing by (z) so that the final...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.