allow integers with floats operations

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

allow integers with floats operations

Post by Psychophanta »

Ideal example:

Code: Select all

a.f=34.
b.l=33
c.f=(1-b&1)*a
Not even this works!!:

Code: Select all

b.l=33
c.f=Int(b&1)
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
User avatar
Michael Vogel
Addict
Addict
Posts: 2797
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Post by Michael Vogel »

Agree, type casting would be cool :wink:

Code: Select all

 
a.f=34. 
b.l=33 
c.f=(float)(1-b&1)*a  
Even certain functions, like float(), double(), long() would be ok, this would be also a workaround for missing functions, like Integer() (oops, again the old story about integer math with abs(), int() etc. :oops: )
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

I would suggest no typecasting, but automatic evaluation depending on the destination type.
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
akj
Enthusiast
Enthusiast
Posts: 668
Joined: Mon Jun 09, 2003 10:08 pm
Location: Nottingham

Post by akj »

Casting can be implemented via small assembler routines. For example in http://www.purebasic.fr/english/viewtopic.php?t=32678 the casting of integer to float is handled with this function:

Code: Select all

Procedure.f Float(i.l)
  Protected Ar.f 
  !FILD dword [p.v_i] 
  !FSTP dword [p.v_Ar] 
  ProcedureReturn Ar 
EndProcedure
But the lack of casting and the lack of [non-conditional] Boolean expressions does highlight some fundamental shortcomings of PureBasic.

I would very much like to see development on PB 4.4 being all about 'Back to Basics'. Stop focussing for a while on the development of sophisticated library routines (welcome though they are) and concentrate on getting the core of PureBasic working properly, especially in the area of arithmetic expressions and mathematics. Virtually every program relies upon arithmetic being 100% reliable and highly convenient, but unfortunately this is not always the case with Pure Basic.

Here are some of the 'Back to Basic' areas that I feel need attention:

* Boolean expressions should be supported in assignment statements

* An expression should be allowed in the STEP clause of FOR

* FOR statements should work with all integer types, including quads

* Pow() and Log() and Log10() should all work at full double accuracy

* (Minor) The operator ' ^ ' should be available for the raising of powers e.g. 2^3

* Some fundamental missing funtions are missing, such as:
Max() Min() Sgn() String() and of course Abs() for integers

* SHAREd variable declarations within procedures should not need an spurious additional DEFINE statement when EnableExplicit is in effect

* Macros still need additional features to be fully useful

The one library that I think should still be improved in a major way is the Date library which I feel is reaching a crisis. It supports dates to only 19-Jan-2038. But this date is now very close. I can no longer use it with database related programs as (for example) the retirement date of many young adults now well exceeds this date. I ended up having to write my own comprehensive set of quad based date/time routines, but I would have preferred to be able to use the built-in routines instead.

Despite all the above negative comments, I really love PureBasic. It was one of the best purchases I ever made.
Last edited by akj on Sat Dec 06, 2008 5:34 pm, edited 1 time in total.
Anthony Jordan
milan1612
Addict
Addict
Posts: 894
Joined: Thu Apr 05, 2007 12:15 am
Location: Nuremberg, Germany
Contact:

Post by milan1612 »

akj wrote:* Boolean expressions should be supported in assignment statements

* An expression should be allowed in the STEP clause of FOR

* FOR statements should work with all integer types, including quads

* Pow() and Log() and Log10() should all work at full double accuracy

* (Minor) The operator ' ^ ' should be available for the raising of powers e.g. 2^3

* Some fundamental missing funtions are missing, such as:
Max() Min() Sgn() String() and of course Abs() for integers
You're mentioning some very important features, the only thing I miss
in this list are unsigned types. Please Fred, focus one of the next versions on
improvements concerning the language itself. :P
Windows 7 & PureBasic 4.4
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

akj wrote:Casting can be implemented via small assembler routines. For example in www.purebasic.fr/english/viewtopic.php?t=32678 the casting of integer to float is handled with this function:Code:
Procedure.f Float(i.l)
Protected Ar.f
!FILD dword [p.v_i]
!FSTP dword [p.v_Ar]
ProcedureReturn Ar
EndProcedure


But the lack of casting and the lack of [non-conditional] Boolean expressions does highlight some fundamental shortcomings of PureBasic.
:shock:
No need ASM for that:

Code: Select all

Procedure.f LtoF(i.l)
  ProcedureReturn i
EndProcedure
etc...
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
Post Reply