What does that mean? how do you represent irrational numbers? or is that arbitrary as in user specified, as different from infinite?
Michael Vanier mvanier@cs.caltech.edu wrote:
Has anyone implemented code for arbitrary precision floating-point numbers in squeak?
Mike
Arbitrary as in user-specified, yes. I'd like a BigFloat class whose numeric precision can be set to anything I want.
I can see two options:
1) Have a pool variable called "precision" and be able to set that when I want to change the precision.
2) Specify the precision separately for each instance of BigFloat.
I think (1) is much better because it's simpler and I don't have to worry so much about operations which combine different precision floats.
The interface might look like:
BigFloat setPrecision: 100. "100 decimal place precision." a := BigFloat fromFloat: 5.0.
Even nicer would be to add lexical support for BigFloats, but that would be much more work.
Mike
From: danielv@netvision.net.il Date: Thu, 31 Oct 2002 21:20:11 +0300
What does that mean? how do you represent irrational numbers? or is that arbitrary as in user specified, as different from infinite?
Michael Vanier mvanier@cs.caltech.edu wrote:
Has anyone implemented code for arbitrary precision floating-point numbers in squeak?
Mike
Care to elaborate?
Mike
From: "Viktor" vi.ki@worldonline.cz Date: Fri, 1 Nov 2002 09:22:14 +0100
The interface might look like:
BigFloat setPrecision: 100. "100 decimal place precision." a := BigFloat fromFloat: 5.0.
Not thread-safe.
V.
"Viktor" vi.ki@worldonline.cz wrote:
The interface might look like:
BigFloat setPrecision: 100. "100 decimal place precision." a := BigFloat fromFloat: 5.0.
Not thread-safe.
It's also not modular. What happens when one module wants 100 places and another wants 1000 ? One of them will win and--especially if it's the one with 100 places--the other module will suffer.
Per-float precision seems to be the most direct thing to do. You have to decide what precision each operation will return. One reasonable thing is to return the precision of the more precise number, but then again some operations may want to increase or decrease precision.
I don't think adding lexical support would be anywhere close to as difficult as implementing all the floating-point operations is going to be! Look at class Scanner.... I guess you might do:
1.1e10p100
For a number with 100 bits of precision.
Oh, and if you specifically want *decimal* numbers, then it is likely that the ANSI ScaledDecimal will do what you want. Except *possibly* for the lexical changes, I think this is available in the Squeak ANSI patches.
-Lex
I agree with your criticisms. However, what I want is to be able to set the float precision on a project-wide basis. In other words, I want to be able to say "all BigFloats now have 10 decimal places" and do some computations. If I suspect that the results are incorrect due to compounding of numerical errors, I want to be able to change this to 100 decimal places in one place only and recompute my results. It may not be thread safe or modular, but it's what I want to be able to do. Having to adjust float precision in a zillion different places is simply unmaintainable.
Mike
From: Lex Spoon lex@cc.gatech.edu Date: Sat, 2 Nov 2002 15:11:08 -0500
"Viktor" vi.ki@worldonline.cz wrote:
The interface might look like:
BigFloat setPrecision: 100. "100 decimal place precision." a := BigFloat fromFloat: 5.0.
Not thread-safe.
It's also not modular. What happens when one module wants 100 places and another wants 1000 ? One of them will win and--especially if it's the one with 100 places--the other module will suffer.
Per-float precision seems to be the most direct thing to do. You have to decide what precision each operation will return. One reasonable thing is to return the precision of the more precise number, but then again some operations may want to increase or decrease precision.
I don't think adding lexical support would be anywhere close to as difficult as implementing all the floating-point operations is going to be! Look at class Scanner.... I guess you might do:
1.1e10p100
For a number with 100 bits of precision.
Oh, and if you specifically want *decimal* numbers, then it is likely that the ANSI ScaledDecimal will do what you want. Except *possibly* for the lexical changes, I think this is available in the Squeak ANSI patches.
-Lex
On Sunday 03 November 2002 01:41 am, Michael Vanier wrote:
I agree with your criticisms. However, what I want is to be able to set the float precision on a project-wide basis. In other words, I want to be able to say "all BigFloats now have 10 decimal places" and do some computations. If I suspect that the results are incorrect due to compounding of numerical errors, I want to be able to change this to 100 decimal places in one place only and recompute my results. It may not be thread safe or modular, but it's what I want to be able to do. Having to adjust float precision in a zillion different places is simply unmaintainable.
Mike
There are rules for when one gains and loses precision by multiplying /Div / Add / sub floating pt numbers together. Any good comp sci book on arbitrary prec floating point techniques contains them.
Why not just make and use a implementation that follows these rules? That way, you never have too much or too little precision... ;)
You can also set it yourself, or subclass from the arb fp class and get that universal precision you want...
-Daniel
Maybe something like this (?):
[some operations] doWithPrecision: 100.
Precision is thread-variable (Thread current precisionOf Floats).
Viktor
I agree with your criticisms. However, what I want is to be able to set the float precision on a project-wide basis. In other words, I want to be able to say "all BigFloats now have 10 decimal places" and do some computations. If I suspect that the results are incorrect due to compounding of numerical errors, I want to be able to change this to 100 decimal places in one place only and recompute my results. It may not be thread safe or modular, but it's what I want to be able to do. Having to adjust float precision in a zillion different places is simply unmaintainable.
Mike
From: Lex Spoon lex@cc.gatech.edu Date: Sat, 2 Nov 2002 15:11:08 -0500
"Viktor" vi.ki@worldonline.cz wrote:
The interface might look like:
BigFloat setPrecision: 100. "100 decimal place precision." a := BigFloat fromFloat: 5.0.
Not thread-safe.
It's also not modular. What happens when one module wants 100 places and another wants 1000 ? One of them will win and--especially if it's the one with 100 places--the other module will suffer.
Per-float precision seems to be the most direct thing to do. You have to decide what precision each operation will return. One reasonable thing is to return the precision of the more precise number, but then again some operations may want to increase or decrease precision.
I don't think adding lexical support would be anywhere close to as difficult as implementing all the floating-point operations is going to be! Look at class Scanner.... I guess you might do:
1.1e10p100
For a number with 100 bits of precision.
Oh, and if you specifically want *decimal* numbers, then it is likely that the ANSI ScaledDecimal will do what you want. Except *possibly* for the lexical changes, I think this is available in the Squeak ANSI patches.
-Lex
Here's the changeset with what I have.
Andres.
"Viktor" vi.ki@worldonline.cz wrote:
Maybe something like this (?):
[some operations] doWithPrecision: 100.
Precision is thread-variable (Thread current precisionOf Floats).
Tempting, but that doesn't handle the case that you call back into another module -- the other module will get your module's floating point precision. I guess we could posit yet a new kind of variable whith is thread-specific *and* module specific....
But in stock Squeak, how about having a variable somewhere that things in your project access whenever they start doing floating point?
x := 1.0 withPrecision: MyProject defaultFloatPrecision.
Incidentally, I don't know that the idea of a single precision is really going to last within a single project.... Is there really just one kind of computation it performs?! Different computations will want different precisions.
Lex
From: Lex Spoon lex@cc.gatech.edu Date: Sun, 3 Nov 2002 19:17:21 -0500
"Viktor" vi.ki@worldonline.cz wrote:
Maybe something like this (?):
[some operations] doWithPrecision: 100.
Precision is thread-variable (Thread current precisionOf Floats).
Tempting, but that doesn't handle the case that you call back into another module -- the other module will get your module's floating point precision. I guess we could posit yet a new kind of variable whith is thread-specific *and* module specific....
But in stock Squeak, how about having a variable somewhere that things in your project access whenever they start doing floating point?
x := 1.0 withPrecision: MyProject defaultFloatPrecision.
This is a nice idea.
Incidentally, I don't know that the idea of a single precision is really going to last within a single project.... Is there really just one kind of computation it performs?! Different computations will want different precisions.
Lex
Well, I'm hoping to have an upper bound on the maximum precision and just use that. It's not that I want 100 digits (say) of precision, but that I want to be more sure about the top ten digits. Of course, what I'm really saying is that I should read a textbook on numerical analysis and roundoff error ;-)
Mike
Maybe something like this (?):
[some operations] doWithPrecision: 100.
Precision is thread-variable (Thread current precisionOf Floats).
Tempting, but that doesn't handle the case that you call back into another module -- the other module will get your module's floating point precision. I guess we could posit yet a new kind of variable whith is thread-specific *and* module specific....
If that module needs specific precision, it will setup own precision of floats at entry point and restore original precision on exit. This is how works proposed
[some operations] doWithPrecision: 100
If the module does not need specific precision, everything is OK.
Viktor
squeak-dev@lists.squeakfoundation.org