Proposal: fixing the 'pure' floating point problem.

2009-03-13 Thread Don
Consider this code: double add(double x, double y) { return x + y; } Is this code pure? Is it nothrow? Technically, it isn't. If you change the floating-point rounding mode on the processor, you get a different result for exactly the same inputs. If you change the floating-point traps, it co

Re: Proposal: fixing the 'pure' floating point problem.

2009-03-13 Thread Denis Koroskin
On Fri, 13 Mar 2009 13:52:08 +0300, Don wrote: Consider this code: double add(double x, double y) { return x + y; } Is this code pure? Is it nothrow? Technically, it isn't. If you change the floating-point rounding mode on the processor, you get a different result for exactly the same in

Re: Proposal: fixing the 'pure' floating point problem.

2009-03-13 Thread Don
Denis Koroskin wrote: On Fri, 13 Mar 2009 13:52:08 +0300, Don wrote: Consider this code: double add(double x, double y) { return x + y; } Is this code pure? Is it nothrow? Technically, it isn't. If you change the floating-point rounding mode on the processor, you get a different result f

Re: Proposal: fixing the 'pure' floating point problem.

2009-03-13 Thread Walter Bright
While it's a good suggestion, I think there's a fundamental problem with it. Suppose a function in the floatingpoint module calls foo() in a non-floatingpoint module which calls std.math.sin(x). std.math.sin(x) is marked as "pure" in a non-floatingpoint module. So, inside foo(), it is assuming

Re: Proposal: fixing the 'pure' floating point problem.

2009-03-13 Thread Christopher Wright
Don wrote: Extend the parametrized module declaration to include something like module(system, floatingpoint) as well as module(system). Is compiler-determined memoization a confirmed feature in a near release? If not, then it doesn't much matter.

Re: Proposal: fixing the 'pure' floating point problem.

2009-03-13 Thread Daniel Keep
Walter Bright wrote: > While it's a good suggestion, I think there's a fundamental problem with > it. Suppose a function in the floatingpoint module calls foo() in a > non-floatingpoint module which calls std.math.sin(x). std.math.sin(x) is > marked as "pure" in a non-floatingpoint module. So, ins

Re: Proposal: fixing the 'pure' floating point problem.

2009-03-13 Thread Jason House
Walter Bright Wrote: > While it's a good suggestion, I think there's a fundamental problem with > it. Suppose a function in the floatingpoint module calls foo() in a > non-floatingpoint module which calls std.math.sin(x). std.math.sin(x) is > marked as "pure" in a non-floatingpoint module. So,

Re: Proposal: fixing the 'pure' floating point problem.

2009-03-13 Thread Walter Bright
Jason House wrote: Walter Bright Wrote: While it's a good suggestion, I think there's a fundamental problem with it. Suppose a function in the floatingpoint module calls foo() in a non-floatingpoint module which calls std.math.sin(x). std.math.sin(x) is marked as "pure" in a non-floatingpoint m

Re: Proposal: fixing the 'pure' floating point problem.

2009-03-13 Thread Don
Walter Bright wrote: While it's a good suggestion, I think there's a fundamental problem with it. Suppose a function in the floatingpoint module calls foo() in a non-floatingpoint module which calls std.math.sin(x). std.math.sin(x) is marked as "pure" in a non-floatingpoint module. So, inside f

Re: Proposal: fixing the 'pure' floating point problem.

2009-03-13 Thread Walter Bright
Don wrote: That's true, but if you're in a floatingpoint module, and you call a non-floatingpoint module, it's your responsibility to make sure that the rounding mode is back to normal. You're saying that you don't care about the status flags. So it's your own fault if you get surprising result

Re: Proposal: fixing the 'pure' floating point problem.

2009-03-14 Thread Don
Walter Bright wrote: Don wrote: That's true, but if you're in a floatingpoint module, and you call a non-floatingpoint module, it's your responsibility to make sure that the rounding mode is back to normal. You're saying that you don't care about the status flags. So it's your own fault if you

Re: Proposal: fixing the 'pure' floating point problem.

2009-03-14 Thread Don
Don wrote: Walter Bright wrote: Don wrote: That's true, but if you're in a floatingpoint module, and you call a non-floatingpoint module, it's your responsibility to make sure that the rounding mode is back to normal. You're saying that you don't care about the status flags. So it's your own

Re: Proposal: fixing the 'pure' floating point problem.

2009-03-14 Thread Walter Bright
Don wrote: Don wrote: Walter Bright wrote: Don wrote: That's true, but if you're in a floatingpoint module, and you call a non-floatingpoint module, it's your responsibility to make sure that the rounding mode is back to normal. You're saying that you don't care about the status flags. So it

Re: Proposal: fixing the 'pure' floating point problem.

2009-03-14 Thread Michel Fortin
On 2009-03-14 02:45:27 -0400, Walter Bright said: Don wrote: That's true, but if you're in a floatingpoint module, and you call a non-floatingpoint module, it's your responsibility to make sure that the rounding mode is back to normal. You're saying that you don't care about the status flags

Re: Proposal: fixing the 'pure' floating point problem.

2009-03-14 Thread Don
Walter Bright wrote: Don wrote: Don wrote: Walter Bright wrote: Don wrote: That's true, but if you're in a floatingpoint module, and you call a non-floatingpoint module, it's your responsibility to make sure that the rounding mode is back to normal. You're saying that you don't care about t

Re: Proposal: fixing the 'pure' floating point problem.

2009-03-14 Thread Don
Michel Fortin wrote: On 2009-03-14 02:45:27 -0400, Walter Bright said: Don wrote: That's true, but if you're in a floatingpoint module, and you call a non-floatingpoint module, it's your responsibility to make sure that the rounding mode is back to normal. You're saying that you don't care

Re: Proposal: fixing the 'pure' floating point problem.

2009-03-14 Thread Andrei Alexandrescu
Walter Bright wrote: Don wrote: The math functions need to work for any rounding mode, not just the default mode. They also set the status flags correctly. In fact, they are almost the only functions where this matters! Ok, then std.math functions cannot be pure in either your or my proposal

Re: Proposal: fixing the 'pure' floating point problem.

2009-03-14 Thread Walter Bright
Don wrote: The math functions need to work for any rounding mode, not just the default mode. They also set the status flags correctly. In fact, they are almost the only functions where this matters! Ok, then std.math functions cannot be pure in either your or my proposal, so I'm not seeing th

Re: Proposal: fixing the 'pure' floating point problem.

2009-03-14 Thread Walter Bright
Andrei Alexandrescu wrote: 1. Is it usual to change the FP flags in an application multiple times, or not? (I never changed them, so please be easy on me.) Given a complex calculation, one might want to know how sensitive the result is to roundoff error. Calculating this exactly can be a daunt

Re: Proposal: fixing the 'pure' floating point problem.

2009-03-14 Thread Joel C. Salomon
Walter Bright wrote: > While it's a good suggestion, I think there's a fundamental problem with > it. Suppose a function in the floatingpoint module calls foo() in a > non-floatingpoint module which calls std.math.sin(x). std.math.sin(x) is > marked as "pure" in a non-floatingpoint module. So, insi

Re: Proposal: fixing the 'pure' floating point problem.

2009-03-14 Thread Joel C. Salomon
Walter Bright wrote: > Andrei Alexandrescu wrote: >> 1. Is it usual to change the FP flags in an application multiple >> times, or not? (I never changed them, so please be easy on me.) > > Given a complex calculation, one might want to know how sensitive the > result is to roundoff error. Calculat

Re: Proposal: fixing the 'pure' floating point problem.

2009-03-14 Thread Don
Walter Bright wrote: Don wrote: The math functions need to work for any rounding mode, not just the default mode. They also set the status flags correctly. In fact, they are almost the only functions where this matters! Ok, then std.math functions cannot be pure in either your or my proposal

Re: Proposal: fixing the 'pure' floating point problem.

2009-03-15 Thread Don
Don wrote: Walter Bright wrote: Don wrote: The math functions need to work for any rounding mode, not just the default mode. They also set the status flags correctly. In fact, they are almost the only functions where this matters! Ok, then std.math functions cannot be pure in either your or

Re: Proposal: fixing the 'pure' floating point problem.

2009-03-15 Thread Walter Bright
Let's say we have A which is in a floatingpoint module, B which is in a non-floatingpoint module and C which is marked pure in a non-floatingpoint module: - module A(floatingpoint); void a() { set mode; b(); restore mode; } module B;

Re: Proposal: fixing the 'pure' floating point problem.

2009-03-15 Thread Don
Walter Bright wrote: Let's say we have A which is in a floatingpoint module, B which is in a non-floatingpoint module and C which is marked pure in a non-floatingpoint module: - module A(floatingpoint); void a() { set mode; b(); restore mode; } -

Re: Proposal: fixing the 'pure' floating point problem.

2009-03-15 Thread bearophile
Joel C. Salomon: > On the 754r mailing list, the HPC crowd was *very* insistent that static > modes be explicitly in the standard. Because in technology lot of things aren't determined on technological merits, but by politics, money and power. Sometimes behind some of the best things you can fin

Re: Proposal: fixing the 'pure' floating point problem.

2009-03-15 Thread Walter Bright
Don wrote: A has called a function in B. B is not a floatingpoint module, so b() can only be called when the mode is set back to the default. a() violates this contract, so a() is incorrect. There's nothing wrong with b() or c(). If a() wants to call b(), it needs to restore the mode first; or

Re: Proposal: fixing the 'pure' floating point problem.

2009-03-15 Thread Daniel Keep
bearophile wrote: > Joel C. Salomon: >> On the 754r mailing list, the HPC crowd was *very* insistent that static >> modes be explicitly in the standard. > > Because in technology lot of things aren't determined on technological > merits, but by politics, money and power. Sometimes behind some o

Re: Proposal: fixing the 'pure' floating point problem.

2009-03-15 Thread Sergey Gromov
Sun, 15 Mar 2009 13:50:07 -0700, Walter Bright wrote: > Don wrote: >> Something interesting about my proposal is that although it is motivated >> by the purity problem, that's simply a rule for the compiler -- the >> rules for programmers do not involve purity at all.(See my other post). >> Do

Re: Proposal: fixing the 'pure' floating point problem.

2009-03-16 Thread Don
Sergey Gromov wrote: Sun, 15 Mar 2009 13:50:07 -0700, Walter Bright wrote: Don wrote: Something interesting about my proposal is that although it is motivated by the purity problem, that's simply a rule for the compiler -- the rules for programmers do not involve purity at all.(See my other p

Re: Proposal: fixing the 'pure' floating point problem.

2009-03-16 Thread Don
Walter Bright wrote: Don wrote: A has called a function in B. B is not a floatingpoint module, so b() can only be called when the mode is set back to the default. a() violates this contract, so a() is incorrect. There's nothing wrong with b() or c(). If a() wants to call b(), it needs to resto

Re: Proposal: fixing the 'pure' floating point problem.

2009-03-16 Thread Michel Fortin
On 2009-03-16 04:03:01 -0400, Don said: In Don's proposal, the following is legal: - module A(floatingpoint); pure void a() { set mode; b(); restore mode; } module B(floatingpoint); pure void b() { do stuff; } ---

Re: Proposal: fixing the 'pure' floating point problem.

2009-03-16 Thread Don
Michel Fortin wrote: On 2009-03-16 04:03:01 -0400, Don said: In Don's proposal, the following is legal: - module A(floatingpoint); pure void a() { set mode; b(); restore mode; } module B(floatingpoint); pure void b() { do st

Re: Proposal: fixing the 'pure' floating point problem.

2009-03-16 Thread Michel Fortin
On 2009-03-16 08:27:28 -0400, Don said: That requires a new keyord, four new calling conventions, a new name mangling scheme, compiler insertion of special code, nasty issues with function pointers, ... Which isn't much different as adding a new extern(x) option, for which all these problem

Re: Proposal: fixing the 'pure' floating point problem.

2009-03-16 Thread Don
Michel Fortin wrote: On 2009-03-16 08:27:28 -0400, Don said: That requires a new keyord, four new calling conventions, a new name mangling scheme, compiler insertion of special code, nasty issues with function pointers, ... Which isn't much different as adding a new extern(x) option, for wh

Re: Proposal: fixing the 'pure' floating point problem.

2009-03-17 Thread Walter Bright
Don wrote: Walter Bright wrote: Don wrote: A has called a function in B. B is not a floatingpoint module, so b() can only be called when the mode is set back to the default. a() violates this contract, so a() is incorrect. There's nothing wrong with b() or c(). If a() wants to call b(), it ne

Re: Proposal: fixing the 'pure' floating point problem.

2009-03-17 Thread Don
Walter Bright wrote: Don wrote: Walter Bright wrote: Don wrote: A has called a function in B. B is not a floatingpoint module, so b() can only be called when the mode is set back to the default. a() violates this contract, so a() is incorrect. There's nothing wrong with b() or c(). If a() wa

Re: Proposal: fixing the 'pure' floating point problem.

2009-03-17 Thread Sergey Gromov
Tue, 17 Mar 2009 03:38:23 -0700, Walter Bright wrote: > Don wrote: >> Walter Bright wrote: >>> Don wrote: A has called a function in B. B is not a floatingpoint module, so b() can only be called when the mode is set back to the default. a() violates this contract, so a() is incorr

Re: Proposal: fixing the 'pure' floating point problem.

2009-04-04 Thread Philip Miess
of course my example makes no sense try pure float square(float x, invariant roundingMode round = default) { return x*x; } in case that helps Phil

Re: Proposal: fixing the 'pure' floating point problem.

2009-04-04 Thread Philip Miess
Walter Bright wrote: Don wrote: That's true, but if you're in a floatingpoint module, and you call a non-floatingpoint module, it's your responsibility to make sure that the rounding mode is back to normal. You're saying that you don't care about the status flags. So it's your own fault if you

Re: Proposal: fixing the 'pure' floating point problem.

2009-04-04 Thread Denis Koroskin
On Sat, 04 Apr 2009 15:19:46 +0400, Philip Miess wrote: of course my example makes no sense try pure float square(float x, invariant roundingMode round = default) { return x*x; } in case that helps Phil I don't see roundingMode used anywhere in your example.

Re: Proposal: fixing the 'pure' floating point problem.

2009-04-04 Thread Don
Philip Miess wrote: Walter Bright wrote: Don wrote: That's true, but if you're in a floatingpoint module, and you call a non-floatingpoint module, it's your responsibility to make sure that the rounding mode is back to normal. You're saying that you don't care about the status flags. So it's

Re: Proposal: fixing the 'pure' floating point problem.

2009-04-10 Thread Philip Miess
Denis Koroskin wrote: On Sat, 04 Apr 2009 15:19:46 +0400, Philip Miess wrote: of course my example makes no sense try pure float square(float x, invariant roundingMode round = default) { return x*x; } in case that helps Phil I don't see roundingMode used anywhere in your example.

Re: Proposal: fixing the 'pure' floating point problem.

2009-04-10 Thread Philip Miess
Don wrote: Philip Miess wrote: Walter Bright wrote: Don wrote: That's true, but if you're in a floatingpoint module, and you call a non-floatingpoint module, it's your responsibility to make sure that the rounding mode is back to normal. You're saying that you don't care about the status fla

Re: Proposal: fixing the 'pure' floating point problem.

2009-04-14 Thread Don
Philip Miess wrote: Don wrote: Philip Miess wrote: Walter Bright wrote: Don wrote: That's true, but if you're in a floatingpoint module, and you call a non-floatingpoint module, it's your responsibility to make sure that the rounding mode is back to normal. You're saying that you don't care