* Why are Emacs integers so small?
@ 2008-05-06 8:00 Davin Pearson
2008-05-06 17:44 ` Peter Dyballa
[not found] ` <mailman.11249.1210095871.18990.help-gnu-emacs@gnu.org>
0 siblings, 2 replies; 3+ messages in thread
From: Davin Pearson @ 2008-05-06 8:00 UTC (permalink / raw)
To: help-gnu-emacs
Why are integers in Elisp restricted on some machines to 27 or 28 bits
of accuracy? Wouldn't it be better if integers could be a full 32
bits in size, by borrowing from the following C++ code and translating
it to C and Elisp.
#include <iostream>
#define null (0)
template<class X>
class ptr
{
private:
X* inner_ptr;
public:
ptr()
{
inner_ptr = null;
}
ptr(const ptr& p)
{
assert(&p != null);
inner_ptr = p.inner_ptr;
if (inner_ptr != null)
{
inner_ptr->ref_count++;
}
}
ptr& operator = (const ptr& p)
{
assert(this != null);
assert(&p != null);
//if (p.inner_ptr != null) // protect against s = s
if (p != null) // protect against s = s
{
p.inner_ptr->ref_count++;
}
if (inner_ptr != null)
{
assert(inner_ptr->ref_count > 0); // protect against double
deletions
inner_ptr->ref_count--;
if (inner_ptr->ref_count == 0)
{
inner_ptr->ref_count = 1; // protect against internal
deletions
delete inner_ptr;
}
}
if (p == null)
{
inner_ptr = null;
}
else
{
inner_ptr = p.inner_ptr;
}
return *this;
}
~ptr()
{
assert(this != null);
if (inner_ptr != null)
{
assert(inner_ptr->ref_count > 0); // protect against double
deletions
inner_ptr->ref_count--;
if (inner_ptr->ref_count == 0)
{
inner_ptr->ref_count = 1; // protect against internal
deletions
delete inner_ptr;
}
inner_ptr = null;
}
}
ptr(X* x)
{
inner_ptr = x;
if (inner_ptr != null)
{
inner_ptr->ref_count++;
}
}
X* operator -> () const
{
assert(this != null);
assert(inner_ptr != null);
return inner_ptr;
}
X& operator * () const
{
assert(this != null);
assert(inner_ptr != null);
return *inner_ptr;
}
X* get_ptr() const
{
assert(this != null);
return inner_ptr;
}
friend bool operator == (const ptr& p1, const ptr& p2)
{
if ((&p1 == null) && (&p2 == null))
{
return true;
}
else if ((&p1 == null) || (&p2 == null))
{
return false;
}
else
{
return (p1.inner_ptr == p2.inner_ptr);
}
}
friend bool operator != (const ptr& p1, const ptr& p2)
{
return !(p1 == p2);
}
};
class Big_Int
{
int ref_count;
template <class T> friend class ptr;
public:
int v;
private:
virtual ~Big_Int()
{
}
private:
Big_Int(int v)
{
this->v = v;
ref_count = 0;
}
public:
static ptr<Big_Int> ctor(int v)
{
return new Big_Int(v);
}
};
int main()
{
ptr<Big_Int> p = Big_Int::ctor(123);
std::cout << "p=" << p->v << '\n';
}
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Why are Emacs integers so small?
2008-05-06 8:00 Why are Emacs integers so small? Davin Pearson
@ 2008-05-06 17:44 ` Peter Dyballa
[not found] ` <mailman.11249.1210095871.18990.help-gnu-emacs@gnu.org>
1 sibling, 0 replies; 3+ messages in thread
From: Peter Dyballa @ 2008-05-06 17:44 UTC (permalink / raw)
To: Davin Pearson; +Cc: help-gnu-emacs
Am 06.05.2008 um 10:00 schrieb Davin Pearson:
> Why are integers in Elisp restricted on some machines to 27 or 28 bits
> of accuracy?
Because some bits (4) are used internally for Lisp purposes. In this
millenium it's so easy to migrate to a useful processor with 64 or
more bits and an operating system that supports these wealth that I
don't see much sense in complaining.
--
Greetings
Pete
The light at the end of the tunnel has been turned off due to budget
cuts.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Why are Emacs integers so small?
[not found] ` <mailman.11249.1210095871.18990.help-gnu-emacs@gnu.org>
@ 2008-05-06 22:41 ` David Kastrup
0 siblings, 0 replies; 3+ messages in thread
From: David Kastrup @ 2008-05-06 22:41 UTC (permalink / raw)
To: help-gnu-emacs
Peter Dyballa <Peter_Dyballa@Web.DE> writes:
> Am 06.05.2008 um 10:00 schrieb Davin Pearson:
>
>> Why are integers in Elisp restricted on some machines to 27 or 28 bits
>> of accuracy?
>
>
> Because some bits (4) are used internally for Lisp purposes. In this
> millenium it's so easy to migrate to a useful processor with 64 or
> more bits and an operating system that supports these wealth that I
> don't see much sense in complaining.
It would be easily possible to use 31 bit integers and use 5 bits for
Lisp purposes (when the lowest bit is 1, we are talking about integers,
or a scheme like that).
--
David Kastrup, Kriemhildstr. 15, 44793 Bochum
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2008-05-06 22:41 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-05-06 8:00 Why are Emacs integers so small? Davin Pearson
2008-05-06 17:44 ` Peter Dyballa
[not found] ` <mailman.11249.1210095871.18990.help-gnu-emacs@gnu.org>
2008-05-06 22:41 ` David Kastrup
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).