The D language

Started by
90 comments, last by Nitage 17 years, 9 months ago
Quote:Original post by Nitage
- IMO the rational for NaN being part of the language instead of the library is covering for the fact that D's comparsion operator can't express the NaN relationship ( ie NaN > NaN, NaN == NaN and NaN < NaN are all false). The language also doesn't account for the fact that many object have a sensible equality relationship, but no sensible greater than or less than relationship


Visit the spec on expressions at: http://digitalmars.com/d/expression.html
Search the page for the text: Floating point comparison operators
You will see a chart of all the relational expressions for float/double/real/etc. Included therein is, for example, (!>=) meaning "Unordered or less than." If you want to test if some variable "foo" is a NaN, then you simply test it against itself for the unordered case:
if (foo !<>= foo) { ... }

Or did I misunderstand the post?

And the equality relationship versus greater/lesser relationship is covered. You overload opEquals for the former and opCmp for the latter. In fact, to use objects as keys in an associative array, you have to provide both of those overloads. opEquals for key matching, and opCmp for the hash tree that implements the array. (There are default implementations of opEquals and opCmp, but I've yet to see any code that relied on them.)

Christopher Nicholson-SaulsD Programming Language | Mango Tree
Advertisement
Quote:
You will see a chart of all the relational expressions for float/double/real/etc. Included therein is, for example, (!>=) meaning "Unordered or less than." If you want to test if some variable "foo" is a NaN, then you simply test it against itself for the unordered case:
if (foo !<>= foo) { ... }

Or did I misunderstand the post?


Say a new floating point standard was created that D didn't natively support. There would be no way of implementing a NaN value for that type. It can be approximated, but D is supposed to remove the need for hacks, not introduce the need.

Quote:
Lack of overloadable assigment operator doesn't prevent implementing reference counting.


Unless you prevent assignment of the handle class then it does.

Quote:
Nobody says GC will solves all the problems.

The D language seems to

Quote:
the rationale for not having C++ like const was that it really doesn't guarantee anything in C++

What with const_cast and reinterpret_cast, nothing uch is guarenteed in C++




It would be nice if C++ integrated some of D's features.

A static if in C++ would remove the need for huge amounts of practically unreadable code for partial template specialization, and it wouldn't break backwards compatability, as the static and if keywords can't legally be placed next to each other at present.

[Edited by - Nitage on July 1, 2006 1:54:24 PM]

This topic is closed to new replies.

Advertisement