Thread overview | ||||||||
---|---|---|---|---|---|---|---|---|
|
November 30, 2004 For v2.0 Fixed Point Arithmetic | ||||
---|---|---|---|---|
| ||||
For many environments it isn't necessary to have floating-point arithmetic. Sometimes it isn't even preferred. There are two solutions, using integral numbers or using fixed-point numbers. Fixed-point arithmetic is normally faster, and, is more stable as floating point numbers because it uses sets of integral numbers to define one fixed-point number. Examples of a possible implementation: fixed f = 10.000; // Has 32-bit integer at the left side, // and a 32-bit integer at the right // side. typedef fixed64 fixed(64,64); fixed64 f2 = 10.000; // Same only with 64 bits at both sides fixed(16,16) f3 = 10.000; // Same only with 16 bits at both sides I hit this while reading the introduction of CUJ, and think that it might be useful for applications who need stability over quantity. Regards, Sjoerd |
November 30, 2004 Re: For v2.0 Fixed Point Arithmetic | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sjoerd van Leent | (sorry, Sjoerd, I think I just sent you an email instead of posting this ...)
Sjoerd van Leent wrote:
> For many environments it isn't necessary to have floating-point arithmetic. Sometimes it isn't even preferred. There are two solutions, using integral numbers or using fixed-point numbers.
>
> Fixed-point arithmetic is normally faster, and, is more stable as floating point numbers because it uses sets of integral numbers to define one fixed-point number.
>
> Examples of a possible implementation:
>
> fixed f = 10.000; // Has 32-bit integer at the left side,
> // and a 32-bit integer at the right
> // side.
>
> typedef fixed64 fixed(64,64);
> fixed64 f2 = 10.000; // Same only with 64 bits at both sides
>
> fixed(16,16) f3 = 10.000; // Same only with 16 bits at both sides
>
> I hit this while reading the introduction of CUJ, and think that it might be useful for applications who need stability over quantity.
>
> Regards,
> Sjoerd
Fixed point arithmetic tends to be *slower* than floating point arithmetics on modern machines.
I also can't quite see why fixed point arithmetic is more stable ...
Holger
|
December 01, 2004 Re: For v2.0 Fixed Point Arithmetic | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sjoerd van Leent | Hi..
> Fixed-point arithmetic is normally faster, and, is more stable as floating point numbers because it uses sets of integral numbers to define one fixed-point number.
It's fairly easy to make a fixed-point template class with all operators overloaded. Why would it have to be a built-in type?
Lionello.
|
December 01, 2004 Re: For v2.0 Fixed Point Arithmetic | ||||
---|---|---|---|---|
| ||||
Posted in reply to Lionello Lunesu | Lionello Lunesu wrote:
> Hi..
>
>>Fixed-point arithmetic is normally faster, and, is more stable as floating point numbers because it uses sets of integral numbers to define one fixed-point number.
>
>
> It's fairly easy to make a fixed-point template class with all operators overloaded. Why would it have to be a built-in type?
>
> Lionello.
>
>
I doesn't have to be a built-in type. It may be just as well a template type of course :-).
Regards,
Sjoerd
|
December 01, 2004 Re: For v2.0 Fixed Point Arithmetic | ||||
---|---|---|---|---|
| ||||
Posted in reply to Holger Sebert | Holger Sebert wrote: > > Fixed point arithmetic tends to be *slower* than floating point arithmetics on modern machines. This is true > > I also can't quite see why fixed point arithmetic is more stable ... > I'll try to explain this. If you've a float with number 0.0 and a float with the outcome of 5.0 divided by 5.0: float float1 = 0.0; float float2 = 5.0/5.0; It is not safe to say: float1 == float2; As you might know, floating-point numbers are not safe in such equations. However, fixed-point numbers are safe. That is why I said that fixed-point arithmetic is more stable as floating-point arithmetic. Of course, since floating-point arithmetic is more fine grained then ever before, it is very well possible to say that it is becoming more stable. But it is not the most stable. > Holger Regards, Sjoerd |
December 02, 2004 Re: For v2.0 Fixed Point Arithmetic | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sjoerd van Leent | 1.0 :-) |
Copyright © 1999-2021 by the D Language Foundation