From 6644736533985058275
X-Google-Thread: f78e5,e4aa14519cca09ff
X-Google-Attributes: gidf78e5,public
X-Google-Language: ENGLISH,ASCII
Path: g2news1.google.com!news4.google.com!newsfeed2.dallas1.level3.net!news.level3.com!newsfeed-00.mathworks.com!peer-uk.news.demon.net!kibo.news.demon.net!news.demon.co.uk!demon!stump.algebra.com!devnull
From: kon@iki.fi (Kalle Olavi Niemitalo)
Newsgroups: comp.std.c++
Subject: Re: My nitpicks on n1774
Date: Mon,  2 May 2005 19:59:24 GMT
Organization: Oulun Puhelin Oyj - Baana
Lines: 110
Sender: mail2news@demon.net
Approved: fjh@cs.mu.oz.au (Fergus Henderson , moderator of comp.std.c++)
Message-ID: <87vf63z31d.fsf@Astalo.kon.iki.fi>
References: <1gvl3nc.1btw8bq15u28exN%thedl0-usenet1@yahoo.com>
 <1114785595.237226.56270@g14g2000cwa.googlegroups.com>
NNTP-Posting-Host: news.news.demon.net
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-15
Content-Transfer-Encoding: quoted-printable
X-Trace: news.demon.co.uk 1115063970 13853 158.152.254.254 (2 May 2005 19:59:30 GMT)
X-Complaints-To: abuse@demon.net
NNTP-Posting-Date: Mon, 2 May 2005 19:59:30 +0000 (UTC)
X-OPOY-MailScanner-SpamCheck: not spam, SpamAssassin (score=1.389,	required 5,
 AWL -0.41, BAYES_50 0.00, UNWANTED_LANGUAGE_BODY 1.80)
X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov)
X-User-Agent: Gnus/5.110003 (No Gnus v0.3) Emacs/22.0.50 (gnu/linux)
X-OPOY-MailScanner-Information: Please contact the OPOY for more information
X-Virus-Scanned: by amavisd-new at cs.mu.OZ.AU
X-OPOY-MailScanner-SpamScore: s
X-Cancel-Lock: sha1:HpNIBs6A0s6NPnrCkfP/57sjS6g=
X-Path: comp-std-cpp-robomod!not-for-mail
X-Received: (from fjh@localhost)
	by mulga.cs.mu.OZ.AU (8.12.10+Sun/8.12.9/Submit) id j42JxOjc020502;
	Tue, 3 May 2005 05:59:24 +1000 (EST)
X-OPOY-MailScanner: Not virus scanned: please contact OPOY for details
X-NNTP-posting-date: Sun, 1 May 2005 09:56:03 +0000 (UTC)
X-Delivered-To: std-c++@ucar.edu
X-Authentication-Warning: mulga.cs.mu.OZ.AU: fjh set sender to devnull@stump.algebra.com using -f
X-MailScanner-From: news@plaza.suomi.net
X-MIME-Autoconverted: from 8bit to quoted-printable by mulga.cs.mu.OZ.AU id j42JxRHb020531
X-Accept-Language: fi;q=1.0, en;q=0.9, sv;q=0.5, de;q=0.1
X-Keywords: std::integer,exception safety,negative zero,Common Lisp,
 std::iostream,std::locale::num_put
X-Newsgroups: comp.std.c++
Xref: g2news1.google.com comp.std.c++:4659

"msalters" <Michiel.Salters@logicacmg.com> writes:

> What's small? I'd say that if the memory allocation fails, the result
> is /by definition/ not small - even if it's just 4 bytes.

I think it is quite odd to throw an overflow_error from a copy
constructor; if the value was OK for one instance of the class,
then it should also fit in others.

Also, I think it will be easier to recover from the exception
(e.g. retry with a different algorithm that allocates less
memory) if it is a bad_alloc rather than overflow_error.  Or
define a new exception class derived from both?

If an exception occurs in a non-const member function, does the
integer object retain its previous value?


[lib.integer.members] #10: Does the constructor also throw if the
string contains no digits, or if the string contains '+' or '-'
anywhere except at the beginning?

[lib.integer.members] #8-#12: There could also be a constructor
that takes a range of chars delimited by two bidirectional
iterators.  Perhaps even remove the conversion from std::string
altogether.  integer(char const*) should still be kept because it
is so convenient with string literals.

[lib.integer.members] #8-#12: The constructor could take the
numeric base as another parameter (int base =3D 10).  When the base
is a power of 2, the complexity can be O(N) in typical
implementations.  I think it'd be better not to add a constructor
integer(char const*, int base), because it'd be too easy to
assume the second parameter is the length of the string.
Possibly allow base=3D=3D0 with the same meaning as in strtol.

[lib.integer.members] #16: The complexity of the copy assignment
operator seems too high; I'd expect O(N).  (First noted by Daniel
Kr=FCgler: Is N the number of bits in the new value, or the sum or
maximum of bits in both values?)

[lib.integer.members] #20: Likewise, the assignment from long
long should perhaps be O(1) like the corresponding constructor.

[lib.integer.members] #25: Preventing out_of_range also requires
a comparison to integer(LONGLONG_MIN).

[lib.integer.members] #26: I dislike the use of "hex" to mean
base 16 rather than 6, even though iostreams already do this.
The specification could at least say "number of hexadecimal
digits".

[lib.integer.member.arithops] #3, #9: Again, what is the N in O(N)?

[lib.integer.member.arithops] #12: I think -=3D and +=3D should have
the same complexity.

[lib.integer.member.arithops] #22, #25, #29: How do *=3D and /=3D
round or truncate the result?

[lib.integer.member.bitops]: I'd like to note that Common Lisp
has arbitrary-size integers and specifies that bitwise and shift
operations must treat them as binary two's complement.  (The
representation in memory is unspecified.)  This means it can have
the equivalent of operator ~ without inconsistencies.

[lib.integer.iostream]:
> "Various applicable formatting state" is something I'm not
> entirely certain about.

- boolalpha: no effect (not bool).
- dec, hex, oct, showbase: would go along nicely with the base
  parameter to the constructor.
- fixed, scientific, showpoint, precision: no effect (not floating point).
- left, internal, right, width: can't be that hard to implement.
- showpos, uppercase, skipws: easy!
- unitbuf: I'm not sure but it looks like this is automatic if
  you don't access the streambuf directly.
- exceptions: Apparently involves catching the overflow_error
  (or bad_alloc) from internal calculations and setting badbit.
- imbue: I think this would require extending std::locale::num_put
  or defining an entirely new facet.
Anything else?

[lib.integer.member.comp] #1: Because the bitwise member
operators do not change the sign, it seems possible to generate a
negative zero.  The current wording for operator =3D=3D makes the
negative zero compare not equal to a positive zero ("sign" is not
written in the font used for identifiers), with a nasty effect on
operator /=3D.

[lib.integer.funs] #2: Should be "returns false if abs(v) <
(integer(1)<<s)" so that negative integers are handled correctly
and the shift does not overflow right away.

[lib.integer.funs] #13: abs returns an rvalue, so I think the
complexity should be at least O(N) as in the copy constructor.

[lib.integer.funs] #16: I presume sqrt(integer(-1)) throws a
domain_error.

[lib.integer.funs] #24: The number of bits in base should have
some effect on the complexity of pow too.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]



