Skip to the content ForoHackers
Log inJoin

My drawer has two thicknesses of shim: 2.0 and 2.00. Java would like a third drawer.

Data structuresJava and the JVMNumerical analysis
#16388 · · Quote · Report

I inherited a tiny repair parts catalogue, completely local and fictional for this example. Two thickness values enter as new BigDecimal("2.0") and new BigDecimal("2.00"). Their compareTo result is zero. Their equals result is false. My HashSet has two entries and the actual bit of steel has begun to look at me in an insolent way.

#16673 · · Quote · Report

What's the question you're asking the steel? "Can either shim fit the same nominal gap?" or "were both marked to the same written precision?" I keep a separate column on a repair ticket for the inscription on an original part.

#16674 · · Quote · Report

Exactly. BigDecimal.equals considers value and scale; compareTo can call them numerically equal. I was using HashSet's equality to answer both questions at once, which is presumably how you achieve a very tidy but fictitious workshop.

#16675 · · Quote · Report

si en la ficha original se veían dos decimales, que no se pierdan aunque la estantería de compra quiera agrupar las dos. si no, dentro de seis meses vas a estar preguntándome cuál proveedor escribió cuál.

#16676 · · Quote · Report

I have kept the printed representation. For the test of nominal numerical equality I compare values explicitly. Now the two source records remain two source records, and our search for this nominal thickness can find either.

#16677 · · Quote · Report

Thank you for saying nominal. Two decimals on a label tell us what was written. They don't, by magic, measure the tolerance of the thing in my hand.

#16678 · · Quote · Report

Quite. Somebody had already begun composing a heroic story about the confidence interval of the printer cartridge.

#16707 · · Quote · Report

Can I have your spare drawer? I collect containers liberated by the establishment of an equivalence relation.

You are not logged in, so this goes up anonymously: no account, no name and no address is stored with it, and it may carry no link and no image. Log in or join to post under your name. Our web server's logs keep the address and time of every request for up to 14 days; to keep yours out of them, use Tor. To reach the staff in confidence, use the drop. Sign as a returning source (a key kept only in this browser)

Sending takes a few seconds here: your browser first works out a proof of work against spam.

Reply