POV-Ray : Newsgroups : povray.unofficial.patches : Why & has higher precedence than + or - in isosurface functions? Server Time
11 Oct 2026 19:41:01 EDT (-0400)
  Why & has higher precedence than + or - in isosurface functions? (Message 1 to 41 of 41)  
From: Warp
Subject: Why & has higher precedence than + or - in isosurface functions?
Date: 31 Jul 2000 09:03:01
Message: <39857905@news.povray.org>
Is there a reason for the operator & having higher precedence than + or -
in isosurface functions?
  The equivalent operator in logic (the one that looks like an upside down 'V')
hasn't, and it would be natural to have the same precedence in isosurface
functions.
  If I write this function:

function { x+y & y+z }

at least I read it in the same way as in mathematics (I'll use '&' here, but
imagine that it's the upside down 'V'):

x+y=0 & y+z=0

  However the current isosurface implementation reads it this way:

x+(y&y)+z

-- 
main(i,_){for(_?--i,main(i+2,"FhhQHFIJD|FQTITFN]zRFHhhTBFHhhTBFysdB"[i]
):_;i&&_>1;printf("%s",_-70?_&1?"[]":" ":(_=0,"\n")),_/=2);} /*- Warp -*/


Post a reply to this message

From: Thorsten Froehlich
Subject: Re: Why & has higher precedence than + or - in isosurface functions?
Date: 31 Jul 2000 12:37:30
Message: <3985ab4a$1@news.povray.org>
In article <39857905@news.povray.org> , Warp <war### [at] tagpovrayorg>  wrote:

> Is there a reason for the operator & having higher precedence than + or - in
> isosurface functions?

This looks like a bug to me, it should have lower precedence.


    Thorsten


____________________________________________________
Thorsten Froehlich, Duisburg, Germany
e-mail: tho### [at] trfde

Visit POV-Ray on the web: http://mac.povray.org


Post a reply to this message

From: pk
Subject: Re: Why & has higher precedence than + or - in isosurface functions?
Date: 31 Jul 2000 14:30:43
Message: <3985C626.46C5B6E8@videotron.ca>
Thorsten Froehlich wrote:
> 
> In article <39857905@news.povray.org> , Warp <war### [at] tagpovrayorg>  wrote:
> 
> > Is there a reason for the operator & having higher precedence than + or - in
> > isosurface functions?
> 
> This looks like a bug to me, it should have lower precedence.
is "&" supposed to be the AND logical operator??It seems so,and if it
is, then it's normal: boolean operator have higher precedence than
arithmetical ones in almost all languages(and Maths); if not, then it's
a bug...

Could somebody explain why the patch uses "^" for something else than
exponents??

HTH,
 Paul
--
AKA paul_virak_khuong at yahoo.com, pkhuong at deja.com, pkhuong at
crosswinds.net and pkhuong at technologist.com(list not complete)...


Post a reply to this message

From: Thorsten Froehlich
Subject: Re: Why & has higher precedence than + or - in isosurface functions?
Date: 31 Jul 2000 14:50:47
Message: <3985ca87@news.povray.org>
In article <3985C626.46C5B6E8@videotron.ca> , pk <thi### [at] videotronca>  
wrote:

> Could somebody explain why the patch uses "^" for something else than
> exponents??

As far as I know it does not use it for anything else...


    Thorsten


____________________________________________________
Thorsten Froehlich, Duisburg, Germany
e-mail: tho### [at] trfde

Visit POV-Ray on the web: http://mac.povray.org


Post a reply to this message

From: pk
Subject: Re: Why & has higher precedence than + or - in isosurface functions?
Date: 31 Jul 2000 14:58:30
Message: <3985CCA9.1452D454@videotron.ca>
Thorsten Froehlich wrote:
> 
> In article <3985C626.46C5B6E8@videotron.ca> , pk <thi### [at] videotronca>
> wrote:
> 
> > Could somebody explain why the patch uses "^" for something else than
> > exponents??
> 
> As far as I know it does not use it for anything else...
Then, why did warp say "^"(that's an inverted V, right?) does the
opposite of &?

Paul
--
AKA paul_virak_khuong at yahoo.com, pkhuong at deja.com, pkhuong at
crosswinds.net and pkhuong at technologist.com(list not complete)...


Post a reply to this message

From: Ron Parker
Subject: Re: Why & has higher precedence than + or - in isosurface functions?
Date: 31 Jul 2000 15:20:05
Message: <slrn8obl55.1qn.ron.parker@fwi.com>
On Mon, 31 Jul 2000 14:59:53 -0400, pk wrote:
>Thorsten Froehlich wrote:
>> 
>> In article <3985C626.46C5B6E8@videotron.ca> , pk <thi### [at] videotronca>
>> wrote:
>> 
>> > Could somebody explain why the patch uses "^" for something else than
>> > exponents??
>> 
>> As far as I know it does not use it for anything else...
>Then, why did warp say "^"(that's an inverted V, right?) does the
>opposite of &?

He was referring to the mathematical symbol that looks like an inverted V.
That symbol represents logical "and", and looks nothing like a caret.

-- 
Ron Parker   http://www2.fwi.com/~parkerr/traces.html
My opinions.  Mine.  Not anyone else's.


Post a reply to this message

From: Peter Popov
Subject: Re: Why & has higher precedence than + or - in isosurface functions?
Date: 31 Jul 2000 15:21:10
Message: <mj1bos4rmn9url4dp0shdmegjdron19h8b@4ax.com>
On 31 Jul 2000 09:03:01 -0400, Warp <war### [at] tagpovrayorg> wrote:

>  Is there a reason for the operator & having higher precedence than + or -
>in isosurface functions?

Well, for me & has always meant binary 'and' or binary multiplication.
As such I find it logical for it to have a higher precedence than
addition. Your mileage may vary but that largely depends on the
programming languages you're most comfortable with :)


Peter Popov ICQ : 15002700
Personal e-mail : pet### [at] usanet
TAG      e-mail : pet### [at] tagpovrayorg


Post a reply to this message

From: Thorsten Froehlich
Subject: Re: Why & has higher precedence than + or - in isosurface functions?
Date: 31 Jul 2000 15:51:58
Message: <3985d8de@news.povray.org>
In article <mj1bos4rmn9url4dp0shdmegjdron19h8b@4ax.com> , Peter Popov 
<pet### [at] usanet>  wrote:

>>  Is there a reason for the operator & having higher precedence than + or -
>>in isosurface functions?
>
> Well, for me & has always meant binary 'and' or binary multiplication.
> As such I find it logical for it to have a higher precedence than
> addition. Your mileage may vary but that largely depends on the
> programming languages you're most comfortable with :)

No, both, binary and logical and should have lower precedence.  If it is
binary it could at most have the same precedence to make any sense at all.
If you look at various programming languages you will find that all current
ones obey the rules set by mathematics.

As for binary operations, I think a dot=and, a plus=or and a line above=not
are very common or even standard.  In this case a 'and' has higher
precedence, but this has little to do with general math and is not related.

The & sign in isosurfaces is obviously the equivalent of the inverted-V, and
thus it should have lower precedence.  As for the not inverted-V, the '|'
(or-sign), I am not sure about the current implementation, but is should
also have lower precedence.


   Thorsten


____________________________________________________
Thorsten Froehlich, Duisburg, Germany
e-mail: tho### [at] trfde

Visit POV-Ray on the web: http://mac.povray.org


Post a reply to this message

From: Warp
Subject: Re: Why & has higher precedence than + or - in isosurface functions?
Date: 1 Aug 2000 06:24:26
Message: <3986a55a@news.povray.org>
Thorsten Froehlich <tho### [at] trfde> wrote:
: The & sign in isosurfaces is obviously the equivalent of the inverted-V, and
: thus it should have lower precedence.  As for the not inverted-V, the '|'
: (or-sign), I am not sure about the current implementation, but is should
: also have lower precedence.

  Also | should have lower precedence than &, so if we have this:

x-y | y-z & x+z

it should be interpreted in this way:

(x-y) | ((y-z) & (x+z))

  In this way it will be consistent with mathematics.

-- 
main(i,_){for(_?--i,main(i+2,"FhhQHFIJD|FQTITFN]zRFHhhTBFHhhTBFysdB"[i]
):_;i&&_>1;printf("%s",_-70?_&1?"[]":" ":(_=0,"\n")),_/=2);} /*- Warp -*/


Post a reply to this message

From: Thorsten Froehlich
Subject: Re: Why & has higher precedence than + or - in isosurface functions?
Date: 1 Aug 2000 07:45:21
Message: <3986b851$1@news.povray.org>
In article <3986a55a@news.povray.org> , Warp <war### [at] tagpovrayorg>  wrote:

>   Also | should have lower precedence than &, so if we have this:
>
> x-y | y-z & x+z
>
> it should be interpreted in this way:
>
> (x-y) | ((y-z) & (x+z))
>
>   In this way it will be consistent with mathematics.

I agree.


____________________________________________________
Thorsten Froehlich, Duisburg, Germany
e-mail: tho### [at] trfde

Visit POV-Ray on the web: http://mac.povray.org


Post a reply to this message

From: Peter Popov
Subject: Re: Why & has higher precedence than + or - in isosurface functions?
Date: 1 Aug 2000 15:54:04
Message: <h24eosk8rdph7u255d2ckk55gckclf374v@4ax.com>
On 1 Aug 2000 06:24:26 -0400, Warp <war### [at] tagpovrayorg> wrote:

>  Also | should have lower precedence than &, so if we have this:
>
>x-y | y-z & x+z
>
>it should be interpreted in this way:
>
>(x-y) | ((y-z) & (x+z))
>
>  In this way it will be consistent with mathematics.

Call me stupid but I've never interpreted it this way. Instead, I'd
have read it thus:

x - ( (y?1:0) | (y?1:0) ) & (x?1:0)) + z

I don't know why, it's just that when I see logic operators I think
it's reasonable for them to expect boolean operands (promoted to
boolean if needed). And with that in mind, I expect multiplication to
have a higher precedence than addition, regardless of context.


Peter Popov ICQ : 15002700
Personal e-mail : pet### [at] usanet
TAG      e-mail : pet### [at] tagpovrayorg


Post a reply to this message

From: pk
Subject: Re: Why & has higher precedence than + or - in isosurface functions?
Date: 1 Aug 2000 17:32:55
Message: <3987425C.687C7484@videotron.ca>
Ron Parker wrote:
> He was referring to the mathematical symbol that looks like an inverted V.
> That symbol represents logical "and", and looks nothing like a caret.
uh... I always thought + meant AND...
So, what's the opposite of AND? NAND? i don't think so....
--
AKA paul_virak_khuong at yahoo.com, pkhuong at deja.com, pkhuong at
crosswinds.net and pkhuong at technologist.com(list not complete)...


Post a reply to this message

From: pk
Subject: Re: Why & has higher precedence than + or - in isosurface functions?
Date: 1 Aug 2000 17:35:30
Message: <398742F7.4946312B@videotron.ca>
pk wrote:
> 
> Ron Parker wrote:
> > He was referring to the mathematical symbol that looks like an inverted V.
> > That symbol represents logical "and", and looks nothing like a caret.
> uh... I always thought + meant AND...
.... i meant to say:"i always thought * (well, dot with valign=center)
meant AND...
> So, what's the opposite of AND? NAND? i don't think so....
--
AKA paul_virak_khuong at yahoo.com, pkhuong at deja.com, pkhuong at
crosswinds.net and pkhuong at technologist.com(list not complete)...


Post a reply to this message

From: Ron Parker
Subject: Re: Why & has higher precedence than + or - in isosurface functions?
Date: 1 Aug 2000 17:52:15
Message: <slrn8oeib9.1u9.ron.parker@fwi.com>
On Tue, 01 Aug 2000 17:36:55 -0400, pk wrote:
>pk wrote:
>> 
>> Ron Parker wrote:
>> > He was referring to the mathematical symbol that looks like an inverted V.
>> > That symbol represents logical "and", and looks nothing like a caret.
>> uh... I always thought + meant AND...
>.... i meant to say:"i always thought * (well, dot with valign=center)
>meant AND...
>> So, what's the opposite of AND? NAND? i don't think so....

Well, the non-inverted V-like symbol that looks like the and symbol means
or.  I'm not sure why you're asking what the opposite is, though.

I suspect that the choice of symbology depends on what sort of logic class
you took.  I encountered the ^/V symbology in my pure mathematics classes,
and the dot/plus symbology in my CS classes.

-- 
Ron Parker   http://www2.fwi.com/~parkerr/traces.html
My opinions.  Mine.  Not anyone else's.


Post a reply to this message

From: pk
Subject: Re: Why & has higher precedence than + or - in isosurface functions?
Date: 1 Aug 2000 18:57:39
Message: <39875639.A2E7C7A2@videotron.ca>
Ron Parker wrote:
> Well, the non-inverted V-like symbol that looks like the and symbol means
> or.  I'm not sure why you're asking what the opposite is, though.
> 
> I suspect that the choice of symbology depends on what sort of logic class
> you took.  I encountered the ^/V symbology in my pure mathematics classes,
> and the dot/plus symbology in my CS classes.
Ok, thanx!
Well, I was asking bc the original poster said something about the
opposite of "V upside down" 8)
And I haven't taken any logic class for the moment, only read some CS
books(CPU design, programming, etc)... It's coming this year, in
maths(I'm just going in 10th grade), so **** I'm gonna be a bit lost if
i don't remember that 8)

Thanks again!
--
AKA paul_virak_khuong at yahoo.com, pkhuong at deja.com, pkhuong at
crosswinds.net and pkhuong at technologist.com(list not complete)...


Post a reply to this message

From: Warp
Subject: Re: Why & has higher precedence than + or - in isosurface functions?
Date: 2 Aug 2000 05:09:57
Message: <3987e565@news.povray.org>
pk <thi### [at] videotronca> wrote:
:> uh... I always thought + meant AND...
: .... i meant to say:"i always thought * (well, dot with valign=center)
: meant AND...

  Nope, they don't mean the same thing.
  The function { x * y } is certainly not the same as function { x & y }
(you can render them if you want to see the difference).
  What you are saying in the first function is that a point <x,y,z> is inside
the shape if and only if x*y < 0.
  The the second case you are saying that a point <x,y,z> is inside the shape
if and only if x < 0 and y < 0.
  For example <-1,2,0> is inside the function { x * y } but it's not inside
the function { x & y }.

  The inverted V-looking operator (and I don't have any reason to believe
that & in isosurface functions is anything else) is a basic operator in
set theory. The same goes for | (which is the V-looking operator in set
theory and denotes union).

:> So, what's the opposite of AND? NAND? i don't think so....

  Basic set theory (I use & and | here because of the lack of the proper
characters):

  The inverse of A&B is -(A&B) ie. (-A)|(-B).

  Here '-' means "not" (ie. "not in the set"). That is, a point is not in
A&B if and only if it's either not in A or not in B (that is, it's not in
both at the same time).

-- 
main(i,_){for(_?--i,main(i+2,"FhhQHFIJD|FQTITFN]zRFHhhTBFHhhTBFysdB"[i]
):_;i&&_>1;printf("%s",_-70?_&1?"[]":" ":(_=0,"\n")),_/=2);} /*- Warp -*/


Post a reply to this message

From: Warp
Subject: Re: Why & has higher precedence than + or - in isosurface functions?
Date: 2 Aug 2000 05:13:18
Message: <3987e62d@news.povray.org>
Peter Popov <pet### [at] usanet> wrote:
: I don't know why, it's just that when I see logic operators I think
: it's reasonable for them to expect boolean operands (promoted to
: boolean if needed). And with that in mind, I expect multiplication to
: have a higher precedence than addition, regardless of context.

  & and | are not boolean operators. The are set theory operators.

  When you write: function { x & y }
you are actually saying:

  x<0 AND y<0

not something like:

  (x LOGICAL_AND y) < 0

which makes little sense.

  What is (0.5 LOGICAL_AND -2.8)?

-- 
main(i,_){for(_?--i,main(i+2,"FhhQHFIJD|FQTITFN]zRFHhhTBFHhhTBFysdB"[i]
):_;i&&_>1;printf("%s",_-70?_&1?"[]":" ":(_=0,"\n")),_/=2);} /*- Warp -*/


Post a reply to this message

From: pk
Subject: Re: Why & has higher precedence than + or - in isosurface functions?
Date: 2 Aug 2000 10:14:06
Message: <39882D08.E5E6F36A@videotron.ca>
Warp wrote:
> 
> pk <thi### [at] videotronca> wrote:
> :> uh... I always thought + meant AND...
> : .... i meant to say:"i always thought * (well, dot with valign=center)
> : meant AND...
> 
>   Nope, they don't mean the same thing.
>   The function { x * y } is certainly not the same as function { x & y }
> (you can render them if you want to see the difference).
>   What you are saying in the first function is that a point <x,y,z> is inside
> the shape if and only if x*y < 0.
>   The the second case you are saying that a point <x,y,z> is inside the shape
> if and only if x < 0 and y < 0.
>   For example <-1,2,0> is inside the function { x * y } but it's not inside
> the function { x & y }.
Yeah, well, as Mr Parker pointed out, logic operators in CS and Logic
Maths aren't the same 8(
In CS, if i remember right, "+" is OR, "*"(well, a dot that's in the
vertical middle of the line) mean AND, and a "-" that's above the line
means not...

I wasn't saying * meant something else than multiply in computer
languages(except maybe APL 8), but that before, in all the litterature
i've read, AND was written the same as you'd write * in algebra...

Can't they make out a standard?!?!?!??!

Oh, well,
 Paul
--
AKA paul_virak_khuong at yahoo.com, pkhuong at deja.com, pkhuong at
crosswinds.net and pkhuong at technologist.com(list not complete)...


Post a reply to this message

From: pk
Subject: Re: Why & has higher precedence than + or - in isosurface functions?
Date: 2 Aug 2000 10:24:36
Message: <39882F7E.6A2B29FE@videotron.ca>
Warp wrote:
> 
> Peter Popov <pet### [at] usanet> wrote:
> : I don't know why, it's just that when I see logic operators I think
> : it's reasonable for them to expect boolean operands (promoted to
> : boolean if needed). And with that in mind, I expect multiplication to
> : have a higher precedence than addition, regardless of context.
> 
>   & and | are not boolean operators. The are set theory operators.
> 
>   When you write: function { x & y }
> you are actually saying:
> 
>   x<0 AND y<0
> 
> not something like:
> 
>   (x LOGICAL_AND y) < 0
> 
> which makes little sense.
> 
>   What is (0.5 LOGICAL_AND -2.8)?
You've never made any programmation before, have you?
In most programming languages, they assign a value to TRUE, and another
to FALSE(in the case above, FALSE=0, and TRUE=NOT(FALSE) )
In other languages, fe, C(for which i dont't really remember the
standard), it's something like TRUE = -1 (binary 11111111) and FALSE
would be 0(binary 00000000)...

And, for your trivia, it depends: most languages will do logical
operations bit by bit, but i suppose that others have a Boolean
type(Java, fe i think), and will undercast it before doing the
LOGICAL_AND
And, yes, doing Logical operations bit by bit can be useful, and anyway,
you can just add a comparison operator before doing the boolean
operation... 

HTH,
 Paul
--
AKA paul_virak_khuong at yahoo.com, pkhuong at deja.com, pkhuong at
crosswinds.net and pkhuong at technologist.com(list not complete)...


Post a reply to this message

From: Peter Popov
Subject: Re: Why & has higher precedence than + or - in isosurface functions?
Date: 2 Aug 2000 10:32:43
Message: <u6cgossjcgm7mm5344obi02n837nqjrm82@4ax.com>
On 2 Aug 2000 05:13:18 -0400, Warp <war### [at] tagpovrayorg> wrote:

>  What is (0.5 LOGICAL_AND -2.8)?

!FALSE :))


Peter Popov ICQ : 15002700
Personal e-mail : pet### [at] usanet
TAG      e-mail : pet### [at] tagpovrayorg


Post a reply to this message

From: Warp
Subject: Re: Why & has higher precedence than + or - in isosurface functions?
Date: 2 Aug 2000 11:02:18
Message: <398837f9@news.povray.org>
It doesn't matter how do you draw the symbol. The meaning should be clear
by now? & is the set theory intersection and | is union, right?

-- 
main(i,_){for(_?--i,main(i+2,"FhhQHFIJD|FQTITFN]zRFHhhTBFHhhTBFysdB"[i]
):_;i&&_>1;printf("%s",_-70?_&1?"[]":" ":(_=0,"\n")),_/=2);} /*- Warp -*/


Post a reply to this message

From: Warp
Subject: Re: Why & has higher precedence than + or - in isosurface functions?
Date: 2 Aug 2000 11:12:16
Message: <39883a4f@news.povray.org>
pk <thi### [at] videotronca> wrote:
: You've never made any programmation before, have you?

  I have been programming for about 10 years.

: In most programming languages, they assign a value to TRUE, and another
: to FALSE(in the case above, FALSE=0, and TRUE=NOT(FALSE) )
: In other languages, fe, C(for which i dont't really remember the
: standard), it's something like TRUE = -1 (binary 11111111) and FALSE
: would be 0(binary 00000000)...

  Nope. In C a true value is 1 (for example the result of the sentence a==b
is 1 if a is equal to b, else 0). When testing a conditional, any value
other than 0 is considered true, and 0 is considered false.

  In this context (0.5 AND -2.8) would be true because none of them is 0.
This, however, has no mathematical meaning whatsoever. It hasn't any meaning
in isosurface functions either (what would a 'true' or 'false' value mean
in a function, may I ask?).

: And, for your trivia, it depends: most languages will do logical
: operations bit by bit, but i suppose that others have a Boolean
: type(Java, fe i think), and will undercast it before doing the
: LOGICAL_AND

  The point is that the & operator in isosurface functions is not even close
to the logical AND-operator of programming languages.

: And, yes, doing Logical operations bit by bit can be useful, and anyway,
: you can just add a comparison operator before doing the boolean
: operation... 

  Firstly, there's no bitwise AND-operator anywhere in the povray language,
and secondly, the &-operator in isosurface functions is neither a logical
nor a bitwise AND-operator.
  It would make no sense in having a logical operator in a function anyways.
Which function is 'true' or 'false'? How do you draw the function { true } ?
  (No, I'm not talking about the povray keyword 'true' here.)

-- 
main(i,_){for(_?--i,main(i+2,"FhhQHFIJD|FQTITFN]zRFHhhTBFHhhTBFysdB"[i]
):_;i&&_>1;printf("%s",_-70?_&1?"[]":" ":(_=0,"\n")),_/=2);} /*- Warp -*/


Post a reply to this message

From: Dick Balaska
Subject: Re: Why & has higher precedence than + or - in isosurface functions?
Date: 2 Aug 2000 11:51:38
Message: <39884355.DCB5F320@buckosoft.com>
Warp wrote:

>   Nope. In C a true value is 1 (for example the result of the sentence a==b
> is 1 if a is equal to b, else 0). When testing a conditional, any value
> other than 0 is considered true, and 0 is considered false.

Your definition is wrong, but your example is correct. :)

False is 0.  True is not false.
1 is a true value, as is 2, as is -1.

I have seen #define TRUE 1
I have also seen #define TRUE ~FALSE

dik


Post a reply to this message

From: pk
Subject: Re: Why & has higher precedence than + or - in isosurface functions?
Date: 2 Aug 2000 11:56:38
Message: <39884510.338B87F5@videotron.ca>
Whoa! sorry! 8)
Warp wrote:
>   Nope. In C a true value is 1 (for example the result of the sentence a==b
> is 1 if a is equal to b, else 0). When testing a conditional, any value
> other than 0 is considered true, and 0 is considered false.
Well, I said i wasn't sure... -1 and 0 must be for Basic, then... 
>   In this context (0.5 AND -2.8) would be true because none of them is 0.
> This, however, has no mathematical meaning whatsoever. It hasn't any meaning
> in isosurface functions either (what would a 'true' or 'false' value mean
> in a function, may I ask?).
TRUE and FALSE having been declared before as constants, TRUE and FLASE
will have values...
>   It would make no sense in having a logical operator in a function anyways.
> Which function is 'true' or 'false'? How do you draw the function { true } ?
>   (No, I'm not talking about the povray keyword 'true' here.)
What do you mean? Isosurfaces are booleans for me: at location <x, y,
z>, there's a point(true, or 1), or there isn't any(false or 0)... So,
you have a function that draw a plane, and another one that draws a
sphere...
You AND them... the result? a circle... You & them... the result? a
circle...
In theory, it might not be the same, but let's ask the person who did
the patch about it...

Anyway, it's getting pretty hot in this thread...

I'm sorry if i offended you by assuming you had no programming
background... it just sounded like you only saw it from the
mathematician pt of view...

Paul
--
AKA paul_virak_khuong at yahoo.com, pkhuong at deja.com, pkhuong at
crosswinds.net and pkhuong at technologist.com(list not complete)...


Post a reply to this message

From: Ron Parker
Subject: Re: Why & has higher precedence than + or - in isosurface functions?
Date: 2 Aug 2000 12:42:16
Message: <slrn8ogkht.8in.ron.parker@fwi.com>
On Wed, 02 Aug 2000 11:50:45 -0400, Dick Balaska wrote:
>Warp wrote:
>
>>   Nope. In C a true value is 1 (for example the result of the sentence a==b
>> is 1 if a is equal to b, else 0). When testing a conditional, any value
>> other than 0 is considered true, and 0 is considered false.
>
>Your definition is wrong, but your example is correct. :)
>
>False is 0.  True is not false.
>1 is a true value, as is 2, as is -1.
>
>I have seen #define TRUE 1
>I have also seen #define TRUE ~FALSE

I prefer #define TRUE (1==1) and #define FALSE (1==0)

-- 
Ron Parker   http://www2.fwi.com/~parkerr/traces.html
My opinions.  Mine.  Not anyone else's.


Post a reply to this message

From: Ron Parker
Subject: Re: Why & has higher precedence than + or - in isosurface functions?
Date: 2 Aug 2000 12:53:12
Message: <slrn8ogl6d.8in.ron.parker@fwi.com>
On Wed, 02 Aug 2000 11:58:08 -0400, pk wrote:
>What do you mean? Isosurfaces are booleans for me: at location <x, y,
>z>, there's a point(true, or 1), or there isn't any(false or 0)... So,
>you have a function that draw a plane, and another one that draws a
>sphere...

More specifically, a point is either inside or outside the isosurface.

>You AND them... the result? a circle... You & them... the result? a
>circle...
>In theory, it might not be the same, but let's ask the person who did
>the patch about it...

Well, in the code, the function that performs that operation is called
"and," but it doesn't use a logical operator to do what it does (it uses
min or max)  Personally, I always think of intersection/union as and/or
anyway, preferring to use CS methods to decompose complex CSG operations.
They're pretty interchangeable at this level, but it's not a mistake
you'd want to make in a higher-level math or CS course.  

-- 
Ron Parker   http://www2.fwi.com/~parkerr/traces.html
My opinions.  Mine.  Not anyone else's.


Post a reply to this message

From: Thorsten Froehlich
Subject: Re: Why & has higher precedence than + or - in isosurface functions?
Date: 2 Aug 2000 14:32:53
Message: <39886955@news.povray.org>
In article <39884355.DCB5F320@buckosoft.com> , Dick Balaska 
<dic### [at] buckosoftcom>  wrote:

>>   Nope. In C a true value is 1 (for example the result of the sentence a==b
>> is 1 if a is equal to b, else 0). When testing a conditional, any value
>> other than 0 is considered true, and 0 is considered false.
>
> Your definition is wrong, but your example is correct. :)
>
> False is 0.  True is not false.
> 1 is a true value, as is 2, as is -1.
>
> I have seen #define TRUE 1
> I have also seen #define TRUE ~FALSE

In C++ he would be nearly right :-)   Except that there is no definition of
the internal representation of the type "bool" which is left to the
compiler/platform (i.e. some RISC platforms like PowerPC have several
condition-code registers and instructions to work with them).

Only conversions from and to "bool" are defined in C++, and in case of the
conversion of bool to anything, true will be "1".


     Thorsten


____________________________________________________
Thorsten Froehlich, Duisburg, Germany
e-mail: tho### [at] trfde

Visit POV-Ray on the web: http://mac.povray.org


Post a reply to this message

From: Peter Popov
Subject: Re: Why & has higher precedence than + or - in isosurface functions?
Date: 2 Aug 2000 18:09:25
Message: <1s6hos89l9r0i1bigu46lb40e6bat72dlv@4ax.com>
On 2 Aug 2000 11:12:16 -0400, Warp <war### [at] tagpovrayorg> wrote:

>  Nope. In C a true value is 1 (for example the result of the sentence a==b
>is 1 if a is equal to b, else 0). When testing a conditional, any value
>other than 0 is considered true, and 0 is considered false.

Why am I thinking that this issue has not been standardised yet?
Because I am wrong again? :)

>  The point is that the & operator in isosurface functions is not even close
>to the logical AND-operator of programming languages.

Ah, so *that* is the point I've been missing all this time! 

Can I have a sign?


Peter Popov ICQ : 15002700
Personal e-mail : pet### [at] usanet
TAG      e-mail : pet### [at] tagpovrayorg


Post a reply to this message

From: Ken
Subject: Re: Why & has higher precedence than + or - in isosurface functions?
Date: 2 Aug 2000 18:15:22
Message: <39889BC2.288D3B69@pacbell.net>
Peter Popov wrote:

> Ah, so *that* is the point I've been missing all this time!
> 
> Can I have a sign?

Ron Popov, please give Peter Parker a sign.

-- 
Ken Tyler - 1400+ POV-Ray, Graphics, 3D Rendering, and Raytracing Links:
http://home.pacbell.net/tylereng/index.html http://www.povray.org/links/


Post a reply to this message

From: Ron Parker
Subject: Re: Why & has higher precedence than + or - in isosurface functions?
Date: 2 Aug 2000 18:54:24
Message: <slrn8ohabq.8q3.ron.parker@fwi.com>
On Wed, 02 Aug 2000 15:08:02 -0700, Ken wrote:
>Ron Popov, please give Peter Parker a sign.

He has one.  It has that cool spider on it.

-- 
Ron Parker   http://www2.fwi.com/~parkerr/traces.html
My opinions.  Mine.  Not anyone else's.


Post a reply to this message

From: Mark Gordon
Subject: Re: Why & has higher precedence than + or - in isosurface functions?
Date: 3 Aug 2000 20:22:50
Message: <398A0D84.245410EE@mailbag.com>
pk wrote:

> In most programming languages, they assign a value to TRUE, and another
> to FALSE(in the case above, FALSE=0, and TRUE=NOT(FALSE) )
> In other languages, fe, C(for which i dont't really remember the
> standard), it's something like TRUE = -1 (binary 11111111) and FALSE
> would be 0(binary 00000000)...

And then there are the Unix shells...

$ true
$ echo $?
0
$ false
$ echo $?
1

Just to keep everyone confused. ;-)

-Mark Gordon


Post a reply to this message

From: Ken
Subject: Re: Why & has higher precedence than + or - in isosurface functions?
Date: 3 Aug 2000 20:28:37
Message: <398A0C7A.AFB04A96@pacbell.net>
Mark Gordon wrote:

> And then there are the Unix shells...
> 
> $ true
> $ echo $?
> 0
> $ false
> $ echo $?
> 1
> 
> Just to keep everyone confused. ;-)

They teach you that at Siggraph 2000 ?

-- 
Ken Tyler - 1400+ POV-Ray, Graphics, 3D Rendering, and Raytracing Links:
http://home.pacbell.net/tylereng/index.html http://www.povray.org/links/


Post a reply to this message

From: Warp
Subject: Re: Why & has higher precedence than + or - in isosurface functions?
Date: 4 Aug 2000 05:51:21
Message: <398a9219@news.povray.org>
Peter Popov <pet### [at] usanet> wrote:
: Why am I thinking that this issue has not been standardised yet?

  What do you mean?
  It is clearly stated in the C and C++ standards.

  If you mean that there's no common standard for all programming languages,
that's only good. If in a specific programming language it's a lot more
natural to state that 'false' is -1 (for example for speed reasons), then
there's no reason to force it to be anything else.

-- 
main(i,_){for(_?--i,main(i+2,"FhhQHFIJD|FQTITFN]zRFHhhTBFHhhTBFysdB"[i]
):_;i&&_>1;printf("%s",_-70?_&1?"[]":" ":(_=0,"\n")),_/=2);} /*- Warp -*/


Post a reply to this message

From: Warp
Subject: Re: Why & has higher precedence than + or - in isosurface functions?
Date: 4 Aug 2000 05:59:05
Message: <398a93e8@news.povray.org>
Dick Balaska <dic### [at] buckosoftcom> wrote:
: I have also seen #define TRUE ~FALSE

  This is horrible. It doesn't work!

  Suppose we have:

#define FALSE 0
#define TRUE ~FALSE

  Then TRUE will be -1 (ie. all bits set).

  Now suppose we want to add a "boolean" type:

typedef int BOOL;

  This will NOT work as it should:

int x=2, y=2;
BOOL b;

b = (x==y);

if(b == TRUE)
  puts("Equal");
else
  puts("Different");


  This will print "Different" although x and y are equal.

-- 
main(i,_){for(_?--i,main(i+2,"FhhQHFIJD|FQTITFN]zRFHhhTBFHhhTBFysdB"[i]
):_;i&&_>1;printf("%s",_-70?_&1?"[]":" ":(_=0,"\n")),_/=2);} /*- Warp -*/


Post a reply to this message

From: Warp
Subject: Re: Why & has higher precedence than + or - in isosurface functions?
Date: 4 Aug 2000 06:05:03
Message: <398a954f@news.povray.org>
pk <thi### [at] videotronca> wrote:
: What do you mean? Isosurfaces are booleans for me: at location <x, y,
: z>, there's a point(true, or 1), or there isn't any(false or 0)... So,
: you have a function that draw a plane, and another one that draws a
: sphere...
: You AND them... the result? a circle... You & them... the result? a
: circle...

  Well, here you are thinking about the set theory union. This has little to
do with the logical and-operator.

  And besides, the logical and-operator in programming languages has lower
precedence than + and - anyways. So in either way you want to think about it,
the current implementation is wrong.

-- 
main(i,_){for(_?--i,main(i+2,"FhhQHFIJD|FQTITFN]zRFHhhTBFHhhTBFysdB"[i]
):_;i&&_>1;printf("%s",_-70?_&1?"[]":" ":(_=0,"\n")),_/=2);} /*- Warp -*/


Post a reply to this message

From: Vahur Krouverk
Subject: Re: Why & has higher precedence than + or - in isosurface functions?
Date: 4 Aug 2000 06:25:44
Message: <398A9A4E.24B1018A@aetec.ee>
Warp wrote:
> 
> Dick Balaska <dic### [at] buckosoftcom> wrote:
> : I have also seen #define TRUE ~FALSE
> 
>   This is horrible. It doesn't work!
> 
>   Suppose we have:
> 
> #define FALSE 0
> #define TRUE ~FALSE
> 
>   Then TRUE will be -1 (ie. all bits set).
> 
>   Now suppose we want to add a "boolean" type:
> 
> typedef int BOOL;
> 
>   This will NOT work as it should:
> 
> int x=2, y=2;
> BOOL b;
> 
> b = (x==y);
> 
> if(b == TRUE)
>   puts("Equal");
> else
>   puts("Different");
> 
>   This will print "Different" although x and y are equal.
> 
It is generally not good idea to compare against #define-d TRUE anyhow.
Better is to use != FALSE (although it is not very readable with its
double negative. Fortunately with C++ bool type this shouldn't be issue
any more.


Post a reply to this message

From: Dick Balaska
Subject: Re: Why & has higher precedence than + or - in isosurface functions?
Date: 6 Aug 2000 02:14:37
Message: <398D0212.8F73338E@buckosoft.com>
Warp wrote:
> 
> Dick Balaska <dic### [at] buckosoftcom> wrote:
> : I have also seen #define TRUE ~FALSE
> 
>   This is horrible. It doesn't work!
> 
>   Suppose we have:
> 
> #define FALSE 0
> #define TRUE ~FALSE
> 
>   Then TRUE will be -1 (ie. all bits set).
> 
>   Now suppose we want to add a "boolean" type:
> 
> typedef int BOOL;
> 
>   This will NOT work as it should:
> 
> int x=2, y=2;
> BOOL b;
> 
> b = (x==y);
> 
> if(b == TRUE)
>   puts("Equal");
> else
>   puts("Different");
> 
>   This will print "Different" although x and y are equal.

You are a young pup.
And you are correct that this doesn't work on 2000 C compilers
because the (user) definition of TRUE doesn't match the system
definition.

But suppose you are working on a 6502 :) or a PDP-11, which can
deal with a -1 much easier than a 1; then it makes sense.
The PDP-11 is big-endian, so when you truncate a 1, you get 0
like down casting from int to word to char.  The -1 always stayed
consistent across casts.

dik


Post a reply to this message

From: Warp
Subject: Re: Why & has higher precedence than + or - in isosurface functions?
Date: 6 Aug 2000 10:47:36
Message: <398d7a88@news.povray.org>
Dick Balaska <dic### [at] buckosoftcom> wrote:
: But suppose you are working on a 6502 :) or a PDP-11, which can
: deal with a -1 much easier than a 1; then it makes sense.
: The PDP-11 is big-endian, so when you truncate a 1, you get 0
: like down casting from int to word to char.  The -1 always stayed
: consistent across casts.

  This can't work this way. If it did, then if you make this:

char c = 1;

the variable 'c' will have the value 0.

  '1' is of type int.

-- 
main(i,_){for(_?--i,main(i+2,"FhhQHFIJD|FQTITFN]zRFHhhTBFHhhTBFysdB"[i]
):_;i&&_>1;printf("%s",_-70?_&1?"[]":" ":(_=0,"\n")),_/=2);} /*- Warp -*/


Post a reply to this message

From: Thorsten Froehlich
Subject: Re: Why & has higher precedence than + or - in isosurface functions?
Date: 6 Aug 2000 14:41:17
Message: <398db14d@news.povray.org>
In article <398d7a88@news.povray.org> , Warp <war### [at] tagpovrayorg>  wrote:

>   This can't work this way. If it did, then if you make this:
>
> char c = 1;
>
> the variable 'c' will have the value 0.
>
>   '1' is of type int.

Sorry, but you are misunderstanding the concepts here:  You have to view the
problem on a lower level than the C programming language.  You have to look
at the hardware:  In case of a memory based CPU architecture, an access to a
int casted to a char will have certain side effects that are usually
"hidden" by a compiler, however, especially in the early days of C it was
common to use the knowledge about the CPU the code would run on to increase
speed.

Even today you can use this trick of CPU dependency, i.e. when you want to
determine the endianess on the fly - simply cast an pointer to an int to a
char and look at the result on different architectures.  After all, C
explicitly allows low level programming; this makes it such an popular
language for implementing operating systems and embedded applications.

A good textbook explaining such issues is "Computer Organization and Design:
The Hardware/Software Interface" (ISBN 1558604286).  It uses the original
(32 bit) MIPS architecture as example for the assembler code (and there is a
software emulator of a simple MIPS system available - even one that runs on
Solaris).  It also explains how high-level language constructs are actually
implemented on the assembly level.  This is in particular useful if you want
to write efficient C/C++ code.
The only negative point is the US$80 price tag.  Anyway, it is available
even in a lot of European university libraries.  Alternatively, there will
surely be a lot of similar, but older books (usually covering the 68000 CPU
architecture) available in next to any library.


    Thorsten


____________________________________________________
Thorsten Froehlich, Duisburg, Germany
e-mail: tho### [at] trfde

Visit POV-Ray on the web: http://mac.povray.org


Post a reply to this message

From: Dick Balaska
Subject: Re: Why & has higher precedence than + or - in isosurface functions?
Date: 6 Aug 2000 20:39:41
Message: <398E0511.E784637@buckosoft.com>
Warp wrote:
> 
>   This can't work this way. If it did, then if you make this:

It works.  It wasn't pretty.

On x86, if you lay out 0x01020304 in memory, it becomes
04 03 02 01  which is what you are used to.
if you read this as a (32 bit) int then you get back your 0x01020304.
Reading it as a char you get 0x04. 
So using TRUE=1 flows naturally with this scheme.
01 00 00 00  is 1 whether read as 8 or 32 bits.

But on a big endian machine, i=0x01020304 is laid out
01 02 03 04.  So if you read (char)i you get 01.

So if (int)i = TRUE=1 or 00 00 00 01, then reading (char)i gives you 0.
So (int)i = TRUE = -1 or FF FF FF FF, gives you non-zero in any size.

Like i said, these were the old days.  Now i believe on Sparcs and 680x0 
there is an implied offset, such that (char)i is read as *((char)i)+3).
Hmm, that seems even weirder; what would ((char)i)+1) give you.
Beats me.  So i took a jaunt through my old K&R and there is no mention
anywhere of TRUE, FALSE, BOOL or boolean.  It does mention that UNIX 
is 16000 lines of C :) and that the assignment
int i 1; /* is legal but deprecated */
Also, the equivilant of += and -= , which is =+ and =- is now frowned upon
for obvious reasons. x =-1;

Old book.

dik


Post a reply to this message

From: Warp
Subject: Re: Why & has higher precedence than + or - in isosurface functions?
Date: 7 Aug 2000 06:06:04
Message: <398e8a0c@news.povray.org>
Thorsten Froehlich <tho### [at] trfde> wrote:
: Sorry, but you are misunderstanding the concepts here:  You have to view the
: problem on a lower level than the C programming language.  You have to look
: at the hardware:  In case of a memory based CPU architecture, an access to a
: int casted to a char will have certain side effects that are usually
: "hidden" by a compiler, however, especially in the early days of C it was
: common to use the knowledge about the CPU the code would run on to increase
: speed.

  I think that a C compiler making this kind of thing (ie. when '1' is casted
to a char, the value '0' results) breaks the ANSI C standard, and thus the
compiler is not an ANSI C one.
  Of course you can use low-level tricks to, for example, get the endianess
of the system, but you can't do many of these tricks without breaking the
standard (usually the standard says about these things that they are undefined
and the compiler can do whatever it wants about them).
  But as you said, specially in embedded systems this kind of freedom makes
C a very versatile language. Not many other languages allow you to, for
example, write directly to a memory location some value.

-- 
main(i,_){for(_?--i,main(i+2,"FhhQHFIJD|FQTITFN]zRFHhhTBFHhhTBFysdB"[i]
):_;i&&_>1;printf("%s",_-70?_&1?"[]":" ":(_=0,"\n")),_/=2);} /*- Warp -*/


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.