Re: Floating point rounding modes: we should restrict them slightly

2009-09-17 Thread Don
Rainer Deyke wrote: Don wrote: Ah. The important thing that makes this work is that the global FP state has a clearly defined default. (round-to-nearest, full precision, no floating point exceptions enabled). Part of the implicit contract of calling a 'memoisable pure' function is that the

Re: Floating point rounding modes: we should restrict them slightly

2009-09-16 Thread Rainer Deyke
Don wrote: Ah. The important thing that makes this work is that the global FP state has a clearly defined default. (round-to-nearest, full precision, no floating point exceptions enabled). Part of the implicit contract of calling a 'memoisable pure' function is that the global FP state is in

Re: Floating point rounding modes: we should restrict them slightly

2009-09-15 Thread Don
Rainer Deyke wrote: Don wrote: Rainer Deyke wrote: Don't forget that uses floating point is a transitive property. Any pure function that calls a pure-but-unmemoisable function is itself pure-but-unmemoisable. This is incorrect. Then I must have misunderstood your proposal. Either you did

Re: Floating point rounding modes: we should restrict them slightly

2009-09-15 Thread Don
Walter Bright wrote: Brad Roberts wrote: Walter Bright wrote: strlen() is safe, while strcpy() and printf() are not. You sure? Does running beyond the bounds of the array if there's no null termination count as safe some how? :) Yes. Memory safety is defined as being free of memory

Re: Floating point rounding modes: we should restrict them slightly

2009-09-15 Thread Rainer Deyke
Don wrote: The thing you missed is that the non-memoisable pure functions can only read the global state. No, I saw that. But if a (pure) function calls another (pure) function that depends on global state, then the first (pure) function also depends on global state. int global_state; pure

Re: Floating point rounding modes: we should restrict them slightly

2009-09-14 Thread Don
Stewart Gordon wrote: Don wrote: snip Floating point settings are just another case of the same thing, except that currently violations in relation to the former are allowed. There's a fundamental difference between them: the floating point settings are a hardware feature and it is

Re: Floating point rounding modes: we should restrict them slightly

2009-09-14 Thread Don
Walter Bright wrote: bearophile wrote: An important purpose of a not bug-prone language is remove as many undefined situations as possible. That's right. If you add that to D2 specs, can the compiler catch at compile time all cases of violations to that rule? Unlikely. But that has to be

Re: Floating point rounding modes: we should restrict them slightly

2009-09-14 Thread Rainer Deyke
Don wrote: The pure function memoisation issue: Certain functions may be marked as 'pure', even though they use floating point (and are therefore dependent on the FP state). The compiler must be able to prevent memoisation of those functions in cases where the rounding mode may have changed.

Re: Floating point rounding modes: we should restrict them slightly

2009-09-14 Thread Walter Bright
Don wrote: Walter Bright wrote: bearophile wrote: An important purpose of a not bug-prone language is remove as many undefined situations as possible. That's right. If you add that to D2 specs, can the compiler catch at compile time all cases of violations to that rule? Unlikely. But

Re: Floating point rounding modes: we should restrict them slightly

2009-09-14 Thread Don
Rainer Deyke wrote: Don wrote: The pure function memoisation issue: Certain functions may be marked as 'pure', even though they use floating point (and are therefore dependent on the FP state). The compiler must be able to prevent memoisation of those functions in cases where the rounding mode

Re: Floating point rounding modes: we should restrict them slightly

2009-09-14 Thread bearophile
Walter Bright: Yes, all the C functions will have to be gone through and separated. strlen() is safe, while strcpy() and printf() are not. For some of the removed functions better C-like ones can be provided: http://www.ddj.com/cpp/214502214 Bye, bearophile

Re: Floating point rounding modes: we should restrict them slightly

2009-09-14 Thread Don
bearophile wrote: Walter Bright: Yes, all the C functions will have to be gone through and separated. strlen() is safe, while strcpy() and printf() are not. For some of the removed functions better C-like ones can be provided: http://www.ddj.com/cpp/214502214 Bye, bearophile Just use D

Re: Floating point rounding modes: we should restrict them slightly

2009-09-14 Thread Jason House
Don Wrote: I've provided very simple solutions for both of these. I'm getting pretty irritated that people are acting as though these are difficult problems and trying to come up with convoluted solutions. Impose minimal semantics and it becomes trivial. FWIW, I've liked your proposals,

Re: Floating point rounding modes: we should restrict them slightly

2009-09-14 Thread Denis Koroskin
On Mon, 14 Sep 2009 16:44:48 +0400, Jason House jason.james.ho...@gmail.com wrote: Don Wrote: I've provided very simple solutions for both of these. I'm getting pretty irritated that people are acting as though these are difficult problems and trying to come up with convoluted solutions.

Re: Floating point rounding modes: we should restrict them slightly

2009-09-14 Thread Brad Roberts
Walter Bright wrote: Don wrote: We could get close, I think. We could catch all violations in SafeD. Disallow calling core.stdc.fenv functions from inside SafeD modules, and provide an RAII object in std.math for changing the rounding mode. Actually there's probably a few other C functions

Re: Floating point rounding modes: we should restrict them slightly

2009-09-14 Thread Walter Bright
Brad Roberts wrote: Walter Bright wrote: strlen() is safe, while strcpy() and printf() are not. You sure? Does running beyond the bounds of the array if there's no null termination count as safe some how? :) Yes. Memory safety is defined as being free of memory corruption errors. Simply

Re: Floating point rounding modes: we should restrict them slightly

2009-09-14 Thread Rainer Deyke
Don wrote: Rainer Deyke wrote: Don't forget that uses floating point is a transitive property. Any pure function that calls a pure-but-unmemoisable function is itself pure-but-unmemoisable. This is incorrect. Then I must have misunderstood your proposal. Either you did a poor job of

Re: Floating point rounding modes: we should restrict them slightly

2009-09-13 Thread Don
Walter Bright wrote: Don wrote: PROPOSAL: Change the spec by adding the line to float.html: If the floating-point rounding mode is changed within a function, it must be restored before the function exits. If this rule is violated (for example, by the use of inline asm), the rounding mode used

Re: Floating point rounding modes: we should restrict them slightly

2009-09-13 Thread Michel Fortin
On 2009-09-13 06:14:02 -0400, Don nos...@nospam.com said: double foo() { return x() + y(); } x() and y() can use whichever rounding modes they like, and if they are impure, they can affect one another, but under this proposal, they cannot change the meaning of the addition inside foo().

Re: Floating point rounding modes: we should restrict them slightly

2009-09-13 Thread Don
Michel Fortin wrote: On 2009-09-13 06:14:02 -0400, Don nos...@nospam.com said: double foo() { return x() + y(); } x() and y() can use whichever rounding modes they like, and if they are impure, they can affect one another, but under this proposal, they cannot change the meaning of the

Re: Floating point rounding modes: we should restrict them slightly

2009-09-13 Thread Walter Bright
Walter Bright wrote: Don wrote: PROPOSAL: Change the spec by adding the line to float.html: If the floating-point rounding mode is changed within a function, it must be restored before the function exits. If this rule is violated (for example, by the use of inline asm), the rounding mode used

Re: Floating point rounding modes: we should restrict them slightly

2009-09-13 Thread Walter Bright
Don wrote: PROPOSAL: Change the spec by adding the line to float.html: If the floating-point rounding mode is changed within a function, it must be restored before the function exits. If this rule is violated (for example, by the use of inline asm), the rounding mode used for subsequent

Re: Floating point rounding modes: we should restrict them slightly

2009-09-13 Thread Stewart Gordon
Don wrote: snip Floating point settings are just another case of the same thing, except that currently violations in relation to the former are allowed. There's a fundamental difference between them: the floating point settings are a hardware feature and it is IMPOSSIBLE to avoid them.

Re: Floating point rounding modes: we should restrict them slightly

2009-09-13 Thread bearophile
Walter Bright: Don: PROPOSAL: Change the spec by adding the line to float.html: If the floating-point rounding mode is changed within a function, it must be restored before the function exits. If this rule is violated (for example, by the use of inline asm), the rounding mode used

Re: Floating point rounding modes: we should restrict them slightly

2009-09-13 Thread Walter Bright
bearophile wrote: An important purpose of a not bug-prone language is remove as many undefined situations as possible. That's right. If you add that to D2 specs, can the compiler catch at compile time all cases of violations to that rule? Unlikely. But that has to be weighed against the

Re: Floating point rounding modes: we should restrict them slightly

2009-09-11 Thread Stewart Gordon
Don wrote: snip LISTING ONE: real x = foo(1) + foo(2) + foo(3); LISTING TWO: real x1 = foo(1); real x2 = foo(2); real x3 = foo(3); real x = x1 + x2 + x3; In C and C++ (and currently in D), they are NOT equivalent! foo() is allowed to change the floating-point rounding mode, so it could

Re: Floating point rounding modes: we should restrict them slightly

2009-09-11 Thread Walter Bright
Don wrote: PROPOSAL: Change the spec by adding the line to float.html: If the floating-point rounding mode is changed within a function, it must be restored before the function exits. If this rule is violated (for example, by the use of inline asm), the rounding mode used for subsequent

Floating point rounding modes: we should restrict them slightly

2009-09-10 Thread Don
A quiz: Conside a function real foo() {} This is not pure, so that it may side-effects, but even so, are listings one and two equivalent? LISTING ONE: real x = foo(1) + foo(2) + foo(3); LISTING TWO: real x1 = foo(1); real x2 = foo(2); real x3 = foo(3); real x = x1 + x2 + x3; In C and

Re: Floating point rounding modes: we should restrict them slightly

2009-09-10 Thread Don
Rainer Deyke wrote: Don wrote: Change the spec by adding the line to float.html: If the floating-point rounding mode is changed within a function, it must be restored before the function exits. Even if that function is called 'fesetround'? Obviously not. In fact, I'd hope to even disallow

Re: Floating point rounding modes: we should restrict them slightly

2009-09-10 Thread Don
#ponce wrote: Why not imposing a rounding mode (ex : toward minus infinity) ? And then disallowing to change it in assembly. You can't impose a rounding mode in a system language: rounding mode is a crucial feature in a few rare but very important cases. The trick is to allow those cases

Re: Floating point rounding modes: we should restrict them slightly

2009-09-10 Thread Jimbob
#ponce alil...@gmail.com wrote in message news:h8adr2$23p...@digitalmars.com... Why not imposing a rounding mode (ex : toward minus infinity) ? And then disallowing to change it in assembly. I mean, you can still do : round(x) as floor(x + 0.5L) ceil(x) as floor(x + 1.0L) Iit would

Re: Floating point rounding modes: we should restrict them slightly

2009-09-10 Thread Michel Fortin
On 2009-09-10 04:24:38 -0400, Don nos...@nospam.com said: PROPOSAL: Change the spec by adding the line to float.html: If the floating-point rounding mode is changed within a function, it must be restored before the function exits. If this rule is violated (for example, by the use of inline

Re: Floating point rounding modes: we should restrict them slightly

2009-09-10 Thread Don
Michel Fortin wrote: On 2009-09-10 04:24:38 -0400, Don nos...@nospam.com said: PROPOSAL: Change the spec by adding the line to float.html: If the floating-point rounding mode is changed within a function, it must be restored before the function exits. If this rule is violated (for example,

Re: Floating point rounding modes: we should restrict them slightly

2009-09-10 Thread Lionello Lunesu
#ponce wrote: Why not imposing a rounding mode (ex : toward minus infinity) ? And then disallowing to change it in assembly. I mean, you can still do : round(x) as floor(x + 0.5L) ceil(x) as floor(x + 1.0L) Iit would cost some precision with large floating-point number, but not much