Click here to Skip to main content
15,895,142 members
Home / Discussions / Algorithms
   

Algorithms

 
GeneralRe: implemented the problem Pin
sumit70344-Aug-08 0:11
sumit70344-Aug-08 0:11 
GeneralRe: implemented the problem Pin
Paul Conrad4-Aug-08 4:57
professionalPaul Conrad4-Aug-08 4:57 
QuestionHow to get a correct string representation of double? Pin
oleg6328-Jul-08 11:28
professionaloleg6328-Jul-08 11:28 
AnswerRe: How to get a correct string representation of double? Pin
Luc Pattyn28-Jul-08 12:27
sitebuilderLuc Pattyn28-Jul-08 12:27 
GeneralRe: How to get a correct string representation of double? Pin
oleg6329-Jul-08 4:24
professionaloleg6329-Jul-08 4:24 
GeneralRe: How to get a correct string representation of double? Pin
CPallini29-Jul-08 7:41
mveCPallini29-Jul-08 7:41 
AnswerRe: How to get a correct string representation of double? Pin
Paul Conrad28-Jul-08 18:19
professionalPaul Conrad28-Jul-08 18:19 
GeneralRe: How to get a correct string representation of double? Pin
ClementsDan31-Jul-08 18:42
ClementsDan31-Jul-08 18:42 
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.)
AnswerRe: How to get a correct string representation of double? Pin
cp987628-Jul-08 22:13
cp987628-Jul-08 22:13 
AnswerRe: How to get a correct string representation of double? Pin
prathapcode3-Jun-09 1:19
prathapcode3-Jun-09 1:19 
GeneralRe: How to get a correct string representation of double? Pin
oleg633-Jun-09 4:04
professionaloleg633-Jun-09 4:04 
QuestionC# code for optimal path, given adjacency matrix/cost values? Pin
sherifffruitfly27-Jul-08 7:08
sherifffruitfly27-Jul-08 7:08 
AnswerRe: C# code for optimal path, given adjacency matrix/cost values? Pin
Tim Craig27-Jul-08 20:09
Tim Craig27-Jul-08 20:09 
GeneralRe: C# code for optimal path, given adjacency matrix/cost values? Pin
sherifffruitfly28-Jul-08 5:22
sherifffruitfly28-Jul-08 5:22 
GeneralRe: C# code for optimal path, given adjacency matrix/cost values? Pin
Paul Conrad28-Jul-08 5:49
professionalPaul Conrad28-Jul-08 5:49 
GeneralRe: C# code for optimal path, given adjacency matrix/cost values? Pin
sherifffruitfly28-Jul-08 9:45
sherifffruitfly28-Jul-08 9:45 
GeneralRe: C# code for optimal path, given adjacency matrix/cost values? Pin
Paul Conrad28-Jul-08 9:48
professionalPaul Conrad28-Jul-08 9:48 
GeneralRe: C# code for optimal path, given adjacency matrix/cost values? Pin
sherifffruitfly29-Jul-08 12:51
sherifffruitfly29-Jul-08 12:51 
QuestionCategorisation Pin
Jammer26-Jul-08 5:33
Jammer26-Jul-08 5:33 
AnswerRe: Categorisation Pin
Alan Balkany28-Jul-08 5:21
Alan Balkany28-Jul-08 5:21 
QuestionHow much different are they? Pin
Ian Uy24-Jul-08 3:45
Ian Uy24-Jul-08 3:45 
AnswerRe: How much different are they? Pin
73Zeppelin24-Jul-08 21:48
73Zeppelin24-Jul-08 21:48 
GeneralRe: How much different are they? Pin
Ian Uy25-Jul-08 16:03
Ian Uy25-Jul-08 16:03 
AnswerRe: How much different are they? Pin
Alan Balkany25-Jul-08 8:20
Alan Balkany25-Jul-08 8:20 
GeneralRe: How much different are they? Pin
Ian Uy25-Jul-08 16:04
Ian Uy25-Jul-08 16:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.