Electronic Schematics (alt.binaries.schematics.electronic) A place to show and share your electronics schematic drawings.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to sci.electronics.design,alt.binaries.schematics.electronic,sci.electronics.cad,sci.electronics.basics
external usenet poster
 
Posts: 2,181
Default IF Statement Notation

Anyone know how to interpret this IF (I think) statement...

PMI=(PM=0)?((PM==0)?1000:PM):PMC

it's in a notation-style I don't understand.

Thanks!

...Jim Thompson
--
| James E.Thompson | mens |
| Analog Innovations | et |
| Analog/Mixed-Signal ASIC's and Discrete Systems | manus |
| San Tan Valley, AZ 85142 Skype: Contacts Only | |
| Voice480)460-2350 Fax: Available upon request | Brass Rat |
| E-mail Icon at http://www.analog-innovations.com | 1962 |

I love to cook with wine. Sometimes I even put it in the food.
  #2   Report Post  
Posted to sci.electronics.design,alt.binaries.schematics.electronic,sci.electronics.cad,sci.electronics.basics
external usenet poster
 
Posts: 119
Default IF Statement Notation

On Thu, 20 Mar 2014 11:51:34 -0700, Jim Thompson wrote:

Anyone know how to interpret this IF (I think) statement...

PMI=(PM=0)?((PM==0)?1000:PM):PMC

it's in a notation-style I don't understand.


It looks like C-style conditional operator (whose use is frowned upon,
particularly in cascade like that).

In C and C++,

ANSWER = THING ? THIS : THAT;

means that if THING is true, ANSWER = THIS. Of THING is false, ANSWER =
THAT.

In more traditional if-else notation, your statement expands to:

if (PM = 0)
{
if (PM == 0)
{
PMI = 1000;
}
else
{
PMI = PM;
}
}
else
{
PMI = PMC;
}

Which packs much less confusion per line, and is therefor much less
desirable from a geeky programmer point of view.

Those limp-wristed busybodies at MISRA have ruled out its use in mission-
critical software, if you can imagine that.

--

Tim Wescott
Wescott Design Services
http://www.wescottdesign.com

  #3   Report Post  
Posted to sci.electronics.design,alt.binaries.schematics.electronic,sci.electronics.cad,sci.electronics.basics
external usenet poster
 
Posts: 2,181
Default IF Statement Notation

On Thu, 20 Mar 2014 14:14:23 -0500, Tim Wescott
wrote:

On Thu, 20 Mar 2014 11:51:34 -0700, Jim Thompson wrote:

Anyone know how to interpret this IF (I think) statement...

PMI=(PM=0)?((PM==0)?1000:PM):PMC

it's in a notation-style I don't understand.


It looks like C-style conditional operator (whose use is frowned upon,
particularly in cascade like that).

In C and C++,

ANSWER = THING ? THIS : THAT;

means that if THING is true, ANSWER = THIS. Of THING is false, ANSWER =
THAT.

In more traditional if-else notation, your statement expands to:

if (PM = 0)
{
if (PM == 0)
{
PMI = 1000;
}
else
{
PMI = PM;
}
}
else
{
PMI = PMC;


In English, does this mean:

If PM is exactly 0, PMI=1000
If PM is greater than 0, PMI=PM
Otherwise (negative PM?) PMI=PMC

I'm confused by the stacking :-(


}

Which packs much less confusion per line, and is therefor much less
desirable from a geeky programmer point of view.

Those limp-wristed busybodies at MISRA have ruled out its use in mission-
critical software, if you can imagine that.


Thanks, Tim! C-notation fits... this is from an HSpice device
library.

...Jim Thompson
--
| James E.Thompson | mens |
| Analog Innovations | et |
| Analog/Mixed-Signal ASIC's and Discrete Systems | manus |
| San Tan Valley, AZ 85142 Skype: Contacts Only | |
| Voice480)460-2350 Fax: Available upon request | Brass Rat |
| E-mail Icon at http://www.analog-innovations.com | 1962 |

I love to cook with wine. Sometimes I even put it in the food.
  #4   Report Post  
Posted to sci.electronics.design,alt.binaries.schematics.electronic,sci.electronics.cad,sci.electronics.basics
external usenet poster
 
Posts: 119
Default IF Statement Notation

On Thu, 20 Mar 2014 12:43:03 -0700, Jim Thompson wrote:

On Thu, 20 Mar 2014 14:14:23 -0500, Tim Wescott
wrote:

On Thu, 20 Mar 2014 11:51:34 -0700, Jim Thompson wrote:

Anyone know how to interpret this IF (I think) statement...

PMI=(PM=0)?((PM==0)?1000:PM):PMC

it's in a notation-style I don't understand.


It looks like C-style conditional operator (whose use is frowned upon,
particularly in cascade like that).

In C and C++,

ANSWER = THING ? THIS : THAT;

means that if THING is true, ANSWER = THIS. Of THING is false, ANSWER =
THAT.

In more traditional if-else notation, your statement expands to:

if (PM = 0)
{
if (PM == 0)
{
PMI = 1000;
}
else {
PMI = PM;
}
}
else {
PMI = PMC;


In English, does this mean:

If PM is exactly 0, PMI=1000
If PM is greater than 0,
PMI=PM Otherwise (negative PM?) PMI=PMC

I'm confused by the stacking :-(


Oh gosh, why should something so clear be confusing?

Yes, that's what it means (which is what JM said).

--

Tim Wescott
Wescott Design Services
http://www.wescottdesign.com

  #5   Report Post  
Posted to sci.electronics.design,alt.binaries.schematics.electronic,sci.electronics.cad,sci.electronics.basics
external usenet poster
 
Posts: 2,701
Default IF Statement Notation

On 20/03/2014 19:14, Tim Wescott wrote:
On Thu, 20 Mar 2014 11:51:34 -0700, Jim Thompson wrote:

Anyone know how to interpret this IF (I think) statement...

PMI=(PM=0)?((PM==0)?1000:PM):PMC

it's in a notation-style I don't understand.


It looks like C-style conditional operator (whose use is frowned upon,
particularly in cascade like that).

In C and C++,

ANSWER = THING ? THIS : THAT;

means that if THING is true, ANSWER = THIS. Of THING is false, ANSWER =
THAT.

In more traditional if-else notation, your statement expands to:

if (PM = 0)
{
if (PM == 0)
{
PMI = 1000;
}
else
{
PMI = PM;
}
}
else
{
PMI = PMC;
}


Although to some extent it would be more readable for a non-programmer
by rewriting it in order of ascending value of PM namely

if (PM0) PMI = PMC
else
{
if (PM==0) PMI = 1000; // in heaven's name why????
else PMI = PM
}

either way it has CCI=3 DP=2
PMI = -1, 0, +1 to test all execution paths

Ironically most machine level compares can do this branch network as a
single comparison and then branching on the sign bit and zero bit.

Which packs much less confusion per line, and is therefor much less
desirable from a geeky programmer point of view.


If there was a serious intention to obfuscate then the variables would
all be called O,I,l,O1,Ol,IO,I0,lO,l0,II,I1,Il, etc.

Those limp-wristed busybodies at MISRA have ruled out its use in mission-
critical software, if you can imagine that.


Unfortunately they can't rule out the possibility of a typo and writing

if (PM=0) doit // which never works

when the intention is

if (PM==0) doit

which is why it is favoured to put the constant as the lhs.

if (0=PM) is then a hard compiler error.

Most modern compilers will catch if (a=b) as potentially dangerous code.

--
Regards,
Martin Brown


  #6   Report Post  
Posted to sci.electronics.design,alt.binaries.schematics.electronic,sci.electronics.cad,sci.electronics.basics
external usenet poster
 
Posts: 2
Default IF Statement Notation

On 24/03/2014 13:55, Martin Brown wrote:
On 20/03/2014 19:14, Tim Wescott wrote:
On Thu, 20 Mar 2014 11:51:34 -0700, Jim Thompson wrote:

Anyone know how to interpret this IF (I think) statement...

PMI=(PM=0)?((PM==0)?1000:PM):PMC

it's in a notation-style I don't understand.


It looks like C-style conditional operator (whose use is frowned upon,
particularly in cascade like that).

In C and C++,

ANSWER = THING ? THIS : THAT;

means that if THING is true, ANSWER = THIS. Of THING is false, ANSWER =
THAT.

In more traditional if-else notation, your statement expands to:

if (PM = 0)
{
if (PM == 0)
{
PMI = 1000;
}
else
{
PMI = PM;
}
}
else
{
PMI = PMC;
}


Although to some extent it would be more readable for a non-programmer
by rewriting it in order of ascending value of PM namely

if (PM0) PMI = PMC
else
{
if (PM==0) PMI = 1000; // in heaven's name why????
else PMI = PM
}

either way it has CCI=3 DP=2
PMI = -1, 0, +1 to test all execution paths

Ironically most machine level compares can do this branch network as a
single comparison and then branching on the sign bit and zero bit.

Which packs much less confusion per line, and is therefor much less
desirable from a geeky programmer point of view.


If there was a serious intention to obfuscate then the variables would
all be called O,I,l,O1,Ol,IO,I0,lO,l0,II,I1,Il, etc.

Those limp-wristed busybodies at MISRA have ruled out its use in mission-
critical software, if you can imagine that.


Unfortunately they can't rule out the possibility of a typo and writing

if (PM=0) doit // which never works

when the intention is

if (PM==0) doit

which is why it is favoured to put the constant as the lhs.

if (0=PM) is then a hard compiler error.

Most modern compilers will catch if (a=b) as potentially dangerous code.


if (PM=0) doit // which never works

is not allowed in MISRA C:2012, Rule 13.4 "The result of an assignment
operator should not be used"

The Keil ARM C compiler always whinges about 'if (assignment)' with a
helpful "did you really mean that" kind of warning.

Michael Kellett

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
A thoughtful statement on WW Bill Woodworking 15 November 2nd 09 10:23 PM
Satellite Position Notation lari UK diy 11 January 17th 07 04:13 PM
Is this statement about Part P correct? jim_in_sussex UK diy 5 May 17th 06 10:28 AM
where to obtain a copy of your HUD statement? [email protected] Home Ownership 2 April 20th 06 04:11 AM
Goncz's Postulate in Compact Notation [email protected] Metalworking 0 August 25th 05 09:46 AM


All times are GMT +1. The time now is 07:57 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 DIYbanter.
The comments are property of their posters.
 

About Us

"It's about DIY & home improvement"