2,313 reputation
411
bio website
location Illinois
age 44
visits member for 2 years, 4 months
seen 15 mins ago

Oct
23
comment Why is float the default in the majority of languages?
@AProgrammer: Actually, I suppose that's my second biggest peeve--the first is the failure of the standard to specify that while the 80-bit type is intended for "temporary computations", any programming language which uses the type for its temporary calculations but fails to expose it to the programmer should be considered broken.
Oct
23
comment Why is float the default in the majority of languages?
@AProgrammer: I've heard about some features in IEEE 754-2008, but I've not seen the standard nor am I aware of any features emerging into programming languages yet. My biggest peeve with IEEE 754 is with its failure to define a set of relational operators that would be suitable for "data processing" [i.e. represent a complete ranking]. I've heard that's supposedly been added, but I've not seen any language or framework which supports it except through rather clunky methods.
Oct
23
comment Why is float the default in the majority of languages?
@AProgrammer: Actually, the approach I would like to see for "arbitrary precision" decimal types would be to use each word to encode nine decimal digits. A number with 10 digits to the left of the decimal and 10 to the right would require four words to store (plus the exponent), with the first and last word holding one digit each, and a little work would be required when rounding off individual digits, but no division longer than 64x32->32r32 would be required except when dividing one big number by another.
Oct
23
comment Why is float the default in the majority of languages?
@AProgrammer: I don't know of any significant use of BCD on any post-1970s processors. People writing games for the Atari 2600 use it a lot because it's generally necessary to convert a score to a string of character pointers in under 150 cycles, which would be way too little time for a binary-to-decimal conversion, but I don't know of any CMOS processors (or, for that matter, any processors other than the NMOS 6502) with a BCD carry chain that can handle more than one digit per cycle. Even the mostly-compatible CMOS version of the 6502 requires an extra cycle when performing BCD math.
Oct
23
comment Why is float the default in the majority of languages?
@AProgrammer: Yes, but division and multiplication is much more expensive than shifting.
Oct
23
comment Testing for object equality by comparing the toString() representations of objects
@AndresF.: Unfortunately, Java has no concept of a type which would be stored as a reference to a Map but be statically bound to different methods. It is necessary instead to create an extra wrapper object and route all actions through it. Doing that is generally semantically superior to requiring that pre-existing types be used in specific ways, but imposes some extra run-time overhead. Often not important, but sometimes devastating.
Oct
23
comment What do you wish language designers paid attention to?
More important than those would be wrapping algebraic ring types (integers that 'wrap around') with defined semantics--similar to C's unsigned integers, but with specified power-of-two wrapping moduli independent of word size.
Oct
23
comment What do you wish language designers paid attention to?
Architecture-dependent features are fine when a language lets a programmer specify what is or is not important. What makes C horrible is that there's no way to declare "numeric type which wraps modulo 65536"; even if a platform implements uint16_t, the standard requires that some implementations regard the difference between two uint16_t values as signed, and that others regard the difference as unsigned; it provides no way for the programmer to specify which behavior is desired.
Oct
23
comment Why is float the default in the majority of languages?
Decimal floating point formats are pretty nasty in a lot of ways, since they require frequent expensive normalization and denormalization steps. The simple act of subtracting two numbers will frequently require that one be divided by a power of ten prior to the subtraction, and may then require that the result be multiplied by a power of ten. Such division and multiplication is much more expensive than shifting.
Oct
23
comment Why are floating point numbers used often in Science/Engineering?
@Octopus: The relative precision is constant within a factor of two; the absolute precision differs drastically. Which is more relevant depends upon the application. When multiplying two numbers, relative precision matters; when adding two numbers, absolute precision matters.
Oct
22
comment Representational Equality versus Value Equality
@Dennis: Defining what identity means is important. If Bob was the name of the person who was wearing suit 430321, then on Tuesday Bob would be the person wearing 430123. If, however, the name Bob was attached the the suit 430321, but also served as shorthand for "whoever is wearing 430321", then on Tuesday Bob would be the person in 430321 (whoever that happened to be) or--if the suit was empty--a "dead" reference [not a dangling reference, since the suit would still exit].
Oct
22
comment Testing for object equality by comparing the toString() representations of objects
The fact that a method accepts an argument of type Map<String, Object> does not imply that it will behave usefully with all instances of that type. If the contract for someMethod specifies that it is only required to behave usefully when the passed-in Map meets certain criteria, including the fact that it maps two particular strings to objects that override toString() in some particular fashion, the fact that Object imposes no particular meaning for toString() would be irrelevant.
Oct
22
comment Why are floating point numbers used often in Science/Engineering?
@kasperd: I think that would depend in some measure upon what operations one was allowed to use in the computation, though I'm not sure how rich a set of computation types one could have and still guarantee that any two arbitrary results that could be produced in a finite number of operations could be compared in bounded time. Algebraic types would almost certainly meet that criterion, but I don't know if ln(x) and exp(x) functions could be added and still meet it.
Oct
22
comment Why are floating point numbers used often in Science/Engineering?
@DanielRHicks: By my understanding, one of the worst problems historically had been exactly what I'm complaining about now: calculations were performed using types which are not exposed to the programmer with deterministic semantics. On the x87 architecture, the fastest way to perform computations is generally to promote all operands to 80 bits, operate on them, and then store any results in whatever form is required. Rounding intermediate results to lower precision slows things down, and also often requires that code use additional calculations which wouldn't otherwise have been necessary.
Oct
22
comment Why are floating point numbers used often in Science/Engineering?
@DanielRHicks: Given 64-bit double values a, b, and c of arbitrary sign, write a method which will compute their sum accurate to +/- 1 ulp if the largest and smallest value are within three orders of magnitude. On my 1980s Pascal compiler, it's easy. Result := a+b+c; Can you offer any approach that's as fast on a platform which doesn't expose the underlying hardware type?
Oct
22
comment Why are floating point numbers used often in Science/Engineering?
@LightnessRacesinOrbit: I'd say more down to compiler and framework vendors being silly. If floating-point hardware provides a means of storing values at whatever precision it uses internally (any decent hardware does), it should be easy for a compiler or framework to offer a datatype whose precision would be specified as being "whatever the hardware uses"; such a datatype would make it easy for programmers to write programs with consistent semantics. The lack of such a type forces programmers that want consistent results to jump through hoops to make their code run needlessly slow.
Oct
21
comment Why are floating point numbers used often in Science/Engineering?
Specify that float and double are storage formats, and real is the computational format. In many systems with no FPU, working with a mantissa, exponent, and flags that are on word and half-word boundaries would be faster than having to unpack and repack doubles with every operation.
Oct
21
comment Why are floating point numbers used often in Science/Engineering?
I've not read Kahan's entire paper yet, but he seems more polite than I would be. Java could have had numerics which were more useful and performed faster than what it actually has if it had added a real type which would take three stack entries to store, and would represent the machine's natural computational precision; the value could be stored as an 80-bit float + 16 bits padding a 64-bit float + 32 bits padding, or 64 bit mantissa, 16 bit exponent, and 16 bits for sign and flags [for non-FPU implementations].
Oct
21
comment Do commercial statistical calculators calculate with a high degree of arbitrary precision or just floating point precision?
There are some cases where accumulated round-off errors and catastrophic cancellation can cause one to loose many bits of precision. If one has software which was written to use the 8087 properly, and calculations would end up dropping 50 bits of precision, then one will end up with about 3 bits of useful precision if calculations were done with 64-bit double, versus about 13 if they were done with a properly-supported 80-bit long double.
Oct
21
comment Why do we still use floats?
Decimal floating-point numbers represent certain values more accurately than binary floating-point numbers, but are inferior in just about every way when dealing with numbers that are not of the form K*10^N for some moderate-sized integer mantissa K and exponent N.