|
Thanks Peter,
1.
What means "a scaled binary integer"?
2.
0.1 is a great sample by you, which could be represented by base 10, but not base 2. Do you have an adverse sample, which could be represented by base 2, but not be able to represented to base 10?
3.
PeterTheSwede wrote: One exception: Binary floating point types can confuse people who don't understand a) that they are binary or b) what that means. Decimal types don't have that issue. In all other respects (precision limits, error accumulation and whatever) they are identical.
I think item a means Float and Double are both using base 2 as internal number represetation, correct? Your point b means?
regards,
George
|
|
|
|
|
George_George wrote: What means "a scaled binary integer"?
It is saved as an integer in binary (base 2) and information about the number of decimals (base 10). So if the number is 12345678 and the number of decimals is 5, the actual value is 123.45678. So... the type works as if it were decimal, while it is in fact "faking" that using a binary representation.
George_George wrote: Do you have an adverse sample, which could be represented by base 2, but not be able to represented to base 10?
No. Never thought about it - I can't even guarantee you that it exists. However, there DO exist values that can't be exactly represented in any base (1/3 or PI are two examples).
George_George wrote: I think item a means Float and Double are both using base 2 as internal number represetation, correct? Your point b means?
Hmmm... let me rephrase it:
Problem "a" with float and double is that people don't understand that they are binary floating-point types.
Problem "b" is that even if people do know that, they don't fully understand what it means.
So... there is no real problem with float and double. The "problem" is with people not understanding what they are and how they work...
Peter the small turnip
(1) It Has To Work. --RFC 1925[^]
|
|
|
|
|
Thanks Peter,
1.
PeterTheSwede wrote: It is saved as an integer in binary (base 2)
"It" you mean Decimal or Float/Double?
2.
PeterTheSwede wrote: o if the number is 12345678 and the number of decimals is 5, the actual value is 123.45678.
Why? How do you get the result 123.45678?
regards,
George
|
|
|
|
|
Hi!
1. I'm talking about System.Decimal (or just decimal in C#). The details are here:
System.Decimal[^]
2. The link explains this as well. This is a quote of the relevant text:
------
A decimal number is a floating-point value that consists of a sign, a numeric value where each digit in the value ranges from 0 to 9, and a scaling factor that indicates the position of a floating decimal point that separates the integral and fractional parts of the numeric value.
The binary representation of a Decimal value consists of a 1-bit sign, a 96-bit integer number, and a scaling factor used to divide the 96-bit integer and specify what portion of it is a decimal fraction. The scaling factor is implicitly the number 10, raised to an exponent ranging from 0 to 28. Therefore, the binary representation of a Decimal value is of the form, ((-2^96 to 2^96) / 10^(0 to 28)), where -2^96-1 is equal to MinValue, and 2^96-1 is equal to MaxValue.
The scaling factor also preserves any trailing zeroes in a Decimal number. Trailing zeroes do not affect the value of a Decimal number in arithmetic or comparison operations. However, trailing zeroes can be revealed by the ToString method if an appropriate format string is applied.
------
So, if the 96-bit integer number is 12345678 and the scaling factor is 5, the number represented is 123.45678 (12345678 / 10^5).
Peter the small turnip
(1) It Has To Work. --RFC 1925[^]
|
|
|
|
|
Thanks Peter,
For float and double, it uses base 2 to represent the value, and the bit is conforming to base 2 -- has value 0 and value 1.
But for the 96-bit used to represent Decimal value, which is in base 10 (from 0 to 9), as the bit has only value 0 and 1, I am wondering how it is represented?
regards,
George
|
|
|
|
|
Hi,
It's explained in the System.Decimal documentation, but if I explain it using other words you may get another chance at grasping it. But beware: it's a trick...
The trick is that the Decimal type stores binary integers (whole numbers) along with the number of decimal digits (the scaling factor) in that integer that belong to the right of the decimal point. As integers convert without rounding problems between binary and decimal, this makes it possible for the Decimal type behave as though it was truly decimal while in fact it is a "hybrid".
And again, the details are in the documentation (I sent you a link previously).
Peter the small turnip
(1) It Has To Work. --RFC 1925[^]
|
|
|
|
|
Great Peter!
I read the document,
a few more comments,
1.
"The Decimal value type is appropriate for financial calculations requiring large numbers of significant integral and fractional digits and no round-off errors." -- I do not agree no rounding error conclusion. Remember we discussed the case when data is realy too large/small which is out of range of Decimal, and the case of infinite numebr like 1/3? Any comments?
2.
"The binary representation of a Decimal value consists of a 1-bit sign, a 96-bit integer number, and a scaling factor used to divide the 96-bit integer and specify what portion of it is a decimal fraction." -- Decimal frantion means the right part of a decimal (right part of the decimal point)?
3.
"binary integers (whole numbers)" -- you mean the whole number (except the decimal point used to scale), for example, 123.456 is stored as base 2 form of 123456 with a scale factor of 3?
Binary integers means integer represented in storage in base 2?
(really sorry for my so many questions, my English is not very good and I am really interested to discuss with you.)
regards,
George
|
|
|
|
|
Hi again!
1. I agree. Like I noted before, there will always be round-off errors as some values can never be represented exactly in any (non-infinite) precision. The Microsoft person who wrote "no round-off errors" probably should have written "no round-off errors caused by conversions between base 2 and base 10" - perhaps he did and some editor cut it down, you never know...
2. Exactly. I think "fraction" is from Latin or Greek, meaning something like "not whole" or "part". The opposite of "integer"/"integral". The value 123.456 consists of an integral part (123) and a fraction (.456).
3. Exactly. 123456 is stored like 11110001001000000. The scaling factor (3, stored as 11 binary) tells us that when the number is converted back to it's decimal representation (123456), the last 3 digits belong to the fraction.
No problem with the many questions - I'm Swedish myself, so I recognize your situation - thirty years in this business does miracles with your English, though, so hang in there! However, I can't promise I'll always have time to answer - but because I find a lot of useful articles here and have professional use for them, I try to spend some time looking for stuff that I can answer - just to give something back to the community.
Peter the small turnip
(1) It Has To Work. --RFC 1925[^]
|
|
|
|
|
It is cool, Peter!
Any other more dedicated forums or newsgroups for discussing about numberic topics to refer? Sometimes, I feel this forum is more for discussion of pure C# programming engineering topics.
regards,
George
|
|
|
|
|
George_George wrote: Any other more dedicated forums or newsgroups for discussing about numberic topics to refer?
On CodeProject, that would be the Mathematics and Algorithms[^] forum. Haven't googled for similar boards elsewhere.
If it's stuff related only to the .NET Framework types (not specifically C#, the System.Decimal and other types we have discussed are the same regardless of language), the .NET Framework[^] forum would be a logical choice.
My best,
Peter the small turnip
(1) It Has To Work. --RFC 1925[^]
|
|
|
|
|
Great Peter!
I have found something interesting related to the topic to share here.
http://en.wikipedia.org/wiki/Rounding[^]
It is mentioned "For example, if an integer divided by 7 is rounded to an integer, a computational rounding error up to 1/14 in the division (which is much more than is possible in typical cases) does not affect the outcome." -- I am confused. I think the rounding error should always be from 0 to 0.5, why the rounding error is up to 1/14?
regards,
George
|
|
|
|
|
Hi all,
i am developing a application for ANPR system. My appliaction using thread pool.registerwaitforsingleobject to grab the frames per 40 msec and signal the other thread for processing the frame. My appliaction has crashing becuase of out of memory error. i am running this appliaction in a hi-spec computer. please find my source below.
Main thread
{
Grabframe gf = new Grabframe();
gf.run();
manualresetevent anprevent = new manualresetevent(false);
.. create instance for anprclass anprobj
anprprocessthread(anprobj.run);
anprprocessthread.start();
}
class Grabframe
{
void run()
{
manualresetevent me = new manualresetevent(false);
waitortimercallback thread_method = waitortimercallback(grabframe);
Threadpool.registerwaitforsingleobject(me,thread_method,stateobj,40,false);
me.set();
}
void grabframe(object state,bool timeinterval)
{
...grab the frame
//signal anpr thread
anprevent.set();
}
}// end class grabframe
//anprthread
class anpr
{
void run()
{
anprevent.waitone();
..do anprprocess
.. get frame from global
}
}// end anpr class
Actually i have tried to reset manualresetevent on threadpool obj 'me' and my application didn't crash but the performance of the anpr is dropped.
please provide me suggestion as soon as possible.
Thanks.
sumathi
|
|
|
|
|
sumathi pandarinathan wrote: My appliaction has crashing becuase of out of memory error.
This is likely related to GDI+ issues. Investigate that code.
|
|
|
|
|
Hi,
i have found the line which is causing out of memory error.
please find the below program and it working similar my application.
namespace ConsoleApplication1
{
/// <summary>
/// Summary description for Class1.
/// </summary>
///
class testclass
{
public void show(Object O)
{
Console.WriteLine("Welcome to C#", "TestClass1 Object");
}
}
class testclass1
{
public void show(Object O)
{
Console.WriteLine("Welcome to ThreadPool", "TestClass2 Object");
}
}
class Example
{
static int CountDown= 20;
public static void WaitToShow(Object Obj, bool signaled)
{
if (Obj != null)
Console.WriteLine(CountDown--);
}
}
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
//
// TODO: Add code to start application here
//
//AutoResetEvent MyEvent = new AutoResetEvent(false);
ManualResetEvent MyEvent = new ManualResetEvent(false);
testclass t1 = new testclass();
testclass1 t2 = new testclass1();
ThreadPool.RegisterWaitForSingleObject(MyEvent, new WaitOrTimerCallback(Example.WaitToShow),t1,40,false);
//ThreadPool.QueueUserWorkItem(new WaitCallback(t1.show));
//ThreadPool.QueueUserWorkItem(new WaitCallback(t2.show));
MyEvent.Set();
Console.WriteLine("****CountDown Program******");
Thread.Sleep(10000);
Console.ReadLine();
}
} // end clas
}
In the above example program, i commented the line " MyEvent.Set();" and doesn't gave me out of memory error. but if i didn't comment it then the appliaction getting crashed.
Actually i need to set manualresetevent, since the performance is very good.
please suggest me any solution for how to avoid increasing memory when i set manualresetevent.
Thanks.
Sumathi
|
|
|
|
|
How do i rename the buttons on a folderbrowserdialog?
|
|
|
|
|
You cannot. You have to build your own custom dialog inheriting from the CommonDialog[^] class.
|
|
|
|
|
You can not rename buttons on folder browser dilaog
|
|
|
|
|
I attended the VS2005 Launch Event and I was told there that with this control, new in 2.0, it was possible to prevent user from uploading a file that is too big.
I can use that feature in my website, but all I could find was the myUploadControl.PostedFile.ContentLength property which is only available AFTER the file has been uploaded.
Of course it would be very stupid to wait untill the user has uploaded his oversized file and then saying "sorry you can't upload this file, it's too big"...
Now I have the problem that, when the user selects e.g. a 5mb file he gets a "page cannot be displayed" instantly because 5mb exceeds the default limit of 4mb in asp.net.
I only want to allow a user to upload files that are maximum 2mb, if he selects a 3mb (or even 4gb) file I want to give him a message that the selected file is too big.
How can I accomplish this ?
|
|
|
|
|
Unfortunately on the server side, in ASP.NET, you can't tell the file size before the request is fully uploaded to the server, because the ASP.NET pipeline is invoked only at that time. When a file is greater than 10 MB (default), the request is killed by the ASP.NET runtime.
I am not aware of any client-side method available for determining the file size, unless you want to use Flash.
|
|
|
|
|
Dario Solera wrote: Flash
Or an ActiveX Control
Or a Java Applet.
Vasudevan Deepak Kumar
Personal Homepage Tech Gossips
A pessimist sees only the dark side of the clouds, and mopes; a philosopher sees both sides, and shrugs; an optimist doesn't see the clouds at all - he's walking on them. --Leonard Louis Levinson
|
|
|
|
|
I am trying to retrieve the all the cells selected by user in the worksheet of Excel using C#. Can anyone help ?
|
|
|
|
|
Varad_Rajan wrote: I am trying to retrieve the all the cells selected by user in the worksheet of Excel using C#.
Why dont you just ask the user? Seriously, without giving us even a hint of what you are doing, will not get you an answer.
|
|
|
|
|
I want to detect if a key is held down during the start up of my program, i.e. in
static void Main()
Is this possible to achieve? I want to make a safe mode that will be entered if the user holds down the shift key when starting the program.
|
|
|
|
|
|
One way I can think of is to add a reference to System.Windows.Forms if you don't have it already and use the following:
static void Main(string[] args)
{
Keys modifiers = Control.ModifierKeys;
Console.WriteLine(modifiers);
}
The modifiers enumeration will have the keys held down (only works for the modifier keys, i.e. Control , Shift , Alt etc).
I doubt it. If it isn't intuitive then we need to fix it. - Chris Maunder
|
|
|
|
|