Author Topic: true and false for bool  (Read 3904 times)

0 Members and 1 Guest are viewing this topic.

kryton9

  • Guest
true and false for bool
« on: June 19, 2011, 08:00:16 PM »
We have the bool type in oxygen, but no corresponding true or false to go with it. Would be a nice addition.

This gives errors:
Code: OxygenBasic
  1. bool f = false
  2. bool t = true
  3.  
  4. print "should be false " f
  5. print "should be true " t

kryton9

  • Guest
Re: true and false for bool
« Reply #1 on: June 19, 2011, 08:16:32 PM »
Also found these sort of oddities as noted in the code.

Code: OxygenBasic
  1. int false = -2
  2. int true = 1
  3.  
  4. bool f = false
  5. bool t = true
  6.  
  7. 'this works
  8. print "should be false " str( not( t ) )
  9. print "should be true "  str( not( f ) )
  10.  
  11. 'this works
  12. print "should be false " str not(t)
  13. print "should be true "  str not(f)
  14.  
  15. 'this doesn't give correct answer
  16. print "should be false " str( not t )
  17. print "should be true "  str( not f )
  18.  
  19. 'this gives errors
  20. 'print "should be false "  not t
  21. 'print "should be true "   not f
  22.  
  23. 'this gives errors also
  24. 'print "should be false "  not( t )
  25. 'print "should be true "  not( f )
« Last Edit: June 19, 2011, 08:21:17 PM by kryton9 »

Charles Pegge

  • Guest
Re: true and false for bool
« Reply #2 on: June 20, 2011, 01:29:42 AM »

I'll take a closer look at this, Kent.

Currently We do not have a true single bit Boolean or a built-in true/false equates.

Boolean will translate to sys and the true condition usually returns -1 and false is always zero.

Any zero value number, including floats is logically evaluated as false, otherwise it is true.

Oxygen will also evaluate empty strings and null strings to false (0) and all other strings to true. (-1)

Charles

kryton9

  • Guest
Re: true and false for bool
« Reply #3 on: June 20, 2011, 03:14:38 AM »
I think there was a typo in your reply Charles, true -1...
anyways here is c++ output for bool   true 1     false 0

[attachment deleted by admin]

Charles Pegge

  • Guest
Re: true and false for bool
« Reply #4 on: June 20, 2011, 08:10:13 AM »

A True sets all the bits in the eax register to 1 including bit 31, the sign bit: hence -1.

Charles

efgee

  • Guest
Re: true and false for bool
« Reply #5 on: June 20, 2011, 05:32:50 PM »
You both are correct:

basic true is -1
c/c++ true is 1

Only hope that if the oxygen compiler sees C code it treats true in c mode not basic.

Personally I prefer:
true 1
false 0
error -1
but nobody would care anyhow...  ;D

Charles Pegge

  • Guest
Re: true and false for bool
« Reply #6 on: June 20, 2011, 08:38:49 PM »

I could mask off all the other bits when returning or assigning bool.

Charles

kryton9

  • Guest
Re: true and false for bool
« Reply #7 on: June 20, 2011, 09:21:53 PM »
I have no idea what that means Charles, but I think matching c++ way will be easier. I will do not on that test case to see what c++ gives.
I saw -2 somewhere in my tests... could have been in oxygen or c++... will post screenshot here.

[attachment deleted by admin]
« Last Edit: June 20, 2011, 09:25:58 PM by kryton9 »