Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: Title formatting help (Read 3596 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Title formatting help

I was playing around with title formatting, and I wanted to use the XOR function for something extremely useful (that mortals would never understand).

So anyways, I played around with the function, but I couldn't get it to do what I wanted. I tried seeing what $xor(1,0) returned - It was not an integer, so I tried doing $if($xor(1,0),1,0), but that returned 0 (1,0 is supposed to return 1).

Is the function broken or am I not using it correctly? Thanks in advance for your helpful advice...

Title formatting help

Reply #1
0 and 1 are just string constants in TAGZ. String constants evaluate to false. Field references (using %x%, $info(), $meta(), or $extra()) evaluate to true if and only if the referenced field is present. In which situation the return value of a non-boolean function evaluates to true, depends on the function. Empty strings as arguments appear to be special.

Examples:

$if($num(0,2),true,false) -> false
$if($num(%tracknumber%,2),true,false) -> true iff tracknumber tag is present
$if($num(1,%tracknumber%),true,false) -> false
$if($not(),true,false) -> false
$if($not(bla),true,false) -> true

Any mortal can find that out with a little experimentation.

Title formatting help

Reply #2
I can't even get this simple statement to work:

$if($num(1),1,0) => 0


Title formatting help

Reply #3
Quote
I can't even get this simple statement to work:

$if($num(1),1,0) => 0


It does exactly what it should.

Title formatting help

Reply #4
Unless you need bitwise XOR, you can use a combination of $add and $mod.

Title formatting help

Reply #5
Ok, I don't understand much of this at all. Do you think you could just show me how to get 1 XOR 0 or 0 XOR 1 to return 1. That's really all I need.

Edit: Just wanted to make it clear that I'm not using any fields or anything - Just numbers.

Title formatting help

Reply #6
Assuming the input numbers will always be 0 or 1, or all you care about is the least significant bit:

$add(0,0) returns 0
$add(1,0) returns 1
$add(0,1) returns 1
$add(1,1) returns 2

Throw $mod(,2) around that $add(), and the 2 becomes 0. Nice and simple... sort of.

Title formatting help

Reply #7
Thanks, but why doesn't the $xor function work properly?

Title formatting help

Reply #8
Quote
Thanks, but why doesn't the $xor function work properly?

It does, when you know how it is supposed to work. It does not perform a bitwise exclusive or of its arguments, rather it performs a logical xor of two truth values. Unfortunately, TAGZ has its own special rules about what is regarded as true and false. For example, it treats the numerical constants 0 and 1 as false.

Moreover, the logical operators in TAGZ return boolean values, with have no printable representation; they are printed as an empty string.

If you want to perform boolean arithmetic with the numbers 0 and 1, you have to simulate this using the arithmetic functions on integers. If a and b are either 0 or 1, you can use the following idioms:

$mod($add(a,b)) -- xor (as described by kode54)
$max(a,b) -- or
$min(a,b) or $mul(a,b) -- and
$sub(1,a) -- not

Title formatting help

Reply #9
Is it not possible to cast between types of values using TagZ?

Quote
$mod($add(a,b)) -- xor (as described by kode54)
$max(a,b) -- or
$min(a,b) or $mul(a,b) -- and
$sub(1,a) -- not


Thanks, that was helpful.