|
No real simple solution due to the way floating point numbers are represented in binary form. You'll always have some odd round off to deal with.
You could always try using the Decimal type...
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
You won't always have round off to deal with. Binary fractions like 1/2, 1/4, 3/4, 1/8, etc. can be exactly represented as a double. But you're right that most numbers can't (assuming that the word "most" can be used of an infinite set).
The reason we put up with the inexactness is that exactness doesn't exist in the physical world. If a piece of wood is "2.4 meters long", it's really "2.4 meters give or take a millimeter" (which would be written as "2.400" to emphasize this). So, then, what difference does it make if your computer represents the length as 2.399999999999999911182158029987476766109466552734375 m, off by a mere 8.88e-17 m, when the physical accuracy is nowhere near that good?
The one exception is money. If something costs $3.99, it costs exactly $3.99, not $3.9900000000000002. If the sales tax is 8.25%, it's exactly 8.25%, not 8.2500000000000004%. And, because we use decimal currency, Decimal classes are often used for monetary amounts.
You could use it as a general-purpose number class, but:
(1) It's not a panacea for rounding error. You still have to deal with 1/3 + 2/3 != 1.
(2) Due to the lack of hardware support, it's much slower than binary floats.
Therefore, I wouldn't just blindly recommend "use Decimal ". If your only complaint with float or double is the string representation, then just use a smaller precision in sprintf or string.Format or the equivalent in your favorite language. (15 digits in the 'g' format will usually get the job done.)
|
|
|
|
|
Read this[^]
Peter
"Until the invention of the computer, the machine gun was the device that enabled humans to make the most mistakes in the smallest amount of time."
|
|
|
|
|
Hi,
I have a string with value "111733394601234567094987654321" . Now i want to divide this with 636. I convert it to double , then im getting 1.1173339460123456E+29 . but these both values are differnt finally im
getting wrong output. can anyone help me.....
Thanks
Prathap
|
|
|
|
|
If you do this for the cryptograpy purposes use any kind of Crypto API, it works with very long integers.
|
|
|
|
|
I know there's lots - but does anyone have favorites, for ease of use and scope?
|
|
|
|
|
You might get better results asking for an algorithm rather than code.
If you don't have the data, you're just another a**hole with an opinion.
|
|
|
|
|
Hahaha! It didn't even occur to me that people would think - quite naturally - that my question was a homework problem! It's been so long since I've been outta school - HAHAHAHA!!
I'm familiar with the standard algorithms (unless a new one has become prominent in the last 10 years) - I was just looking to save myself the hassle with a lil homebrew tool for a game (eve).
Nevermind - thanks for being nice about it tho!
(giggles) Homework.
|
|
|
|
|
sherifffruitfly wrote: question was a homework problem
Typically this type of problem is a homework problem for an algorithms class. Sounds like it isn't in your case.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
Yupyup - It's all good - I should have realized how my question would appear to the reader.
|
|
|
|
|
To qualify as a homework problem, it need to have plz, urgent, hlp me, or any variation of a time constrained desperation.
I did find the Hamiltonian Cycle algorithm my Algorithms professor did a few years ago, a real fun one to read back through, but it works
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
hahaha - yeah, gamer-speak is definitely typical. Lots of exclamation marks too!!!elevens!!!
|
|
|
|
|
Hi,
I'm just looking to rework part of an application I'm working on that catgorises files by comparing the file path and file name to a lookup table table with multiple string values. Are there any established patterns or algorithms that apply to this scenario?
Something along the lines of how Levenshtien Distance works for comparing two strings, the difference here being that I'm looking at whole words compared to an array of possible matches.
Cheers,
|
|
|
|
|
Why can't you use the Levenshtein distance with words, i.e. increment the cost for a different word instead of a letter? You could even use fractional costs according to how much the words differ.
|
|
|
|
|
Good Day,
Is there a mathematical formula/theory that can tell how much different (in numbers or percentage) two objects are?
Say, I have 2 files, File A and File B, and the formula can tell how much are they different?
Regards,
Ian
It is said that the most complex structures built by mankind are software systems. This is not generally appreciated because most people cannot see them. Maybe that's a good thing because if we saw them as buildings, we'd deem many of them unsafe.
|
|
|
|
|
You need some kind of metric by which to measure the difference. For example, length. Text files could differ by the number of different words if you are comparing an original file with a modified one.
So you need to specify what, exactly, you imply by "differ".
|
|
|
|
|
Well, I will be comparing binary data. A string of 1's and 0's.
It is said that the most complex structures built by mankind are software systems. This is not generally appreciated because most people cannot see them. Maybe that's a good thing because if we saw them as buildings, we'd deem many of them unsafe.
|
|
|
|
|
|
Thank you. But I would be comparing binary data. But this is somewhat along the line of what I need.
It is said that the most complex structures built by mankind are software systems. This is not generally appreciated because most people cannot see them. Maybe that's a good thing because if we saw them as buildings, we'd deem many of them unsafe.
|
|
|
|
|
You still have to define "different".
Say file REF holds 99 bytes of data.
File APPEND holds the same 99 bytes of data followed by one more byte.
File PREFIX holds that same one byte followed by the original 99 bytes.
Now these three files are different. How different are they? That is up to you.
One would say APPEND is very similar to REF.
One could argue PREFIX is completely different, or very similar. Take your pick.
And some parsers would object to "very similar"; if REF represents a valid image (say something
Image.FromFile understands), then APPEND is not likely to be a valid image (as per Image.FromFile).
|
|
|
|
|
I see.
I thought there was a general formula to test for "difference".
It is said that the most complex structures built by mankind are software systems. This is not generally appreciated because most people cannot see them. Maybe that's a good thing because if we saw them as buildings, we'd deem many of them unsafe.
|
|
|
|
|
It depends on what your goal is.
|
|
|
|
|
how about the binary correlation. sum of results where bits equal gives 1 and not equal gives -1 total divided by # bits in file should be useful.
|
|
|
|
|
As I said, it depends what your goal is. If this metric is useful for you, go for it.
|
|
|
|
|
I want to implement FDIST function in c#. Can any one tell me what is the formula to calculate FDIST. its arguments are :-
FDIST(x,degrees_freedom1,degrees_freedom2)
X is the value at which to evaluate the function.
Degrees_freedom1 is the numerator degrees of freedom.
Degrees_freedom2 is the denominator degrees of freedom.
thanks in advance
|
|
|
|