Forum > General

C not and ternary conversion to pascal question.

(1/6) > >>

jamie:
I have this in a C++ app which kind of throwing me off a little.


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---A_Double = ! (The Condition Test) ? 0:Some_Double_Variable;  
Normally I would say that the "!" operator is generating a True/1 , False/0 value. But that wouldn't make any sense because
why bother with the "Some_Double_Variable" where You can simply specify it directly.

So basically the ! reverses the results but to generate a True/False  or 1/0 results.

But I don't think this is what's happening here.

Can someone shead some light on it?

is it simply reversing the results of the ternary or is it generating a 1 or 0 results?


jamie:
I think i figured it out.

Its first negating the operation and then follows the actual selection.

I don't know why it just didn't swap the selections around!

or maybe I still have it wrong! :(

TRon:
You mean like this?

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program test; const  Some_Double_Variable = 1.23456;  Condition_Test_Value = true; function CIFF(condition: boolean; trueval, falseval: double): double;begin  if condition    then CIFF := trueval else CIFF := falseval;end; function The_Condition_Test: boolean;begin  The_Condition_Test := Condition_Test_Value;end; procedure tern1;var  A_Double: double;begin  if not The_Condition_Test    then A_Double := 0 else A_Double := Some_Double_Variable;  writeln('A_Double = ', A_Double:2:6);end; procedure tern2;var  A_Double: double;begin  A_Double := CIFF(not The_Condition_Test, 0, Some_Double_Variable);  writeln('A_Double = ', A_Double:2:6);end; begin  tern1;  tern2;end. 

Zvoni:
If not condition then adouble:=0 else adouble:=somedouble;

MarkMLl:

--- Quote from: jamie on September 24, 2024, 02:52:50 am ---Its first negating the operation and then follows the actual selection.

--- End quote ---

That's nasty, because some notations require a boolean predicate/test (i.e. a comparison etc.) to be in parentheses.

I think you've got it right, but I'd look very carefully at those values /in/ /case/ they are in any way demonic (I don't think "magical" is appropriate here) and there's something in there to catch the unwary... or that relies on a precedence quirk in the originally-used compiler.

MarkMLl

Navigation

[0] Message Index

[#] Next page

Go to full version