Page 2 of 2 FirstFirst 12
Results 11 to 17 of 17

Thread: ThinBasic extended numbers in FreeBASIC SDK.

  1. #11
    hello Charles
    for some time I have been thinking about translating some long double io routines that were placed in the public domain by Stephen L Moshier the author of the cephes math library, I can't find the file anymore by using Google but the name of the file was ioldouble.c, anyway here's the translation so far, not complete and not perfect.

    here's the C file and the FreeBASIC translation
    Attached Files Attached Files
    Last edited by jack; 15-05-2011 at 00:23.

  2. #12
    Thanks Jack,

    Long quad looks interesting. This could be useful in physics and anything requiring super-high precision in the real world. I think this would also translate quite easily into Oxygen with few alterations to the original C.

    I noticed there are are many short integers involved. I wonder if we could take advantage of 32 bits and considerably improve performance.

    Charles

  3. #13
    using 32-bit is likely to speed things up, but would take considerable work.
    I still need to go over my translation and clean things up.
    one line of code that caused me to almost give up was this line in the sub edivm
    if( (tdenm * 0xffffL) < tnum )
    
    where tdenm is an unsigned short and tnum is unsigned long
    looks inocent enough but I had to cast tdenm to ulong to get it to work properly.
    Last edited by jack; 06-05-2011 at 03:50.

  4. #14
    Oxygen would have trouble with this too since it does not currently cast integer literals to be long or short. Therefore the left side expression is treated as 16 bit and a 16 bit unsigned comparison is made between left side and right side.

    What happens if you use a dword variable instead of &hffff literal? You may be able to avoid casting.

    Charles

  5. #15
    Charles, here's the output of the following test program with the cast to ulong in place
    dim as ushort ip(NI-1)
    dim as string s
    dim as integer i
    ? "Pi    = ";etoasc(@epi(0), 20)
    ediv(@eten(0),@epi(0),@ip(0))
    ? "Pi/10 = ";etoasc(@ip(0), 20)
    ? "1.0   = ";etoasc(@eone(0), 20)
    emul(@epi(0), @epi(0), @ip(0))
    ? "Pi^2  = ";etoasc(@ip(0), 20)
    for i=4 to 20
        ? etoasc(@epi(0), i)
    next
    Print "Press RETURN to end ";
    sleep
    
    Pi = 3.14159265358979323846e0
    Pi/10 = 3.14159265358979323846e-1
    1.0 = 1.00000000000000000000e0
    Pi^2 = 9.86960440108935861883e0
    3.1416e0
    3.14159e0
    3.141593e0
    3.1415927e0
    3.14159265e0
    3.141592654e0
    3.1415926536e0
    3.14159265359e0
    3.141592653590e0
    3.1415926535898e0
    3.14159265358979e0
    3.141592653589793e0
    3.1415926535897932e0
    3.14159265358979324e0
    3.141592653589793238e0
    3.1415926535897932385e0
    3.14159265358979323846e0
    Press RETURN to end
    if I take out the cast statement afore mentioned you get this (using a long variable instead of &hffffL makes no difference)
    Pi = 2.68427263874999999985e15
    Pi/10 = 2.19895614566399999988e19
    1.0 = 1.00000000000000000000e0
    Pi^2 = 1.16411769059045078135e6
    2.6843e15
    2.68427e15
    2.684273e15
    2.6842726e15
    2.68427264e15
    2.684272639e15
    2.6842726387e15
    2.68427263875e15
    2.684272638750e15
    2.6842726387500e15
    2.68427263875000e15
    2.684272638750000e15
    2.6842726387500000e15
    2.68427263875000000e15
    2.684272638750000000e15
    2.6842726387499999999e15
    2.68427263874999999985e15
    Press RETURN to end
    the L suffix does not appear to be important but the cast is.
    it took me quite some time to find the cause of the problem.
    [edit]
    if I change the order of the operands to larger first then it works without casting
    that is, instead of
    if (cast(ulong, tdenm) * &hffffL) < tnum then
    
    to
    if  tnum >=(tdenm * &hffffL) then
    
    it works
    [/edit]
    Last edited by jack; 07-05-2011 at 01:15.

  6. #16
    Jack,

    Definitely a bug in FreeBasic since the Left side expression should be upgraded from 16 bits to 32 bits when the long variable is encountered.


    I tested this situation with Oxygen and found to my satisfaction that it treated the condition correctly.

    However I soon lost my complacency when I realised that the type casting is determined only by the left side. Both Left and right sides should be considered to ensure that the higher type is used on both sides of the comparator.

    Then there is the issue of comparing Longs with Dwords...

    Anyway I'm grateful that you have raised the issue.

    Charles

  7. #17
    I updated the translation, added string and number conversions, it's complete enough to update my real10 package.

    updated file is above.

Page 2 of 2 FirstFirst 12

Similar Threads

  1. FreeBasic SDK: extended data type
    By ErosOlmi in forum Module SDK (Freebasic version)
    Replies: 29
    Last Post: 15-09-2008, 20:47

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •