Shop OBEX P1 Docs P2 Docs Learn Events
QLOG fixed point output versus SPIN2 floating point? — Parallax Forums

QLOG fixed point output versus SPIN2 floating point?

Has anyone come up with a slick way of converting QLOG's fixed point result to SPIN2 floating point format?

Comments

  • Have you tried using floating point log() in FlexC, compiling and looking at the disassembly? IIRC, FlexC uses the CORDIC unit for floating point math, at least QMUL, QDIV and SQRT. I haven't tested exp() and log(), so far.

  • ersmithersmith Posts: 6,259

    No need to look at the disassembly, the source code for __builtin_log2f and __builtin_exp2f are in the FlexProp include/libsys/powers.c file. They're not highly optimized, but I think they work OK.

  • @bob_g4bby said:
    Has anyone come up with a slick way of converting QLOG's fixed point result to SPIN2 floating point format?

    You can convert QLOG’s fixed-point output to SPIN2 floating point by using the built-in FlexProp C functions __builtin_log2f and __builtin_exp2f. They handle the math in floating point and can serve directly in SPIN2 via inline C or compiled functions. Alternatively, implementing a simple scaling from Q format to float before applying log() in Spin2 also works.

  • cgraceycgracey Posts: 14,293

    The latest versions of Spin2 (found in PNut, Pnut-TS, and PropTools, I believe) have several new log and exp functions that work in floating point.

  • Thanks, Chip - that'll be used in the spectrum display on the radio receiver I'm working on. Log amplitude is the norm.

  • RaymanRayman Posts: 16,072

    Anybody know how qlog and qexp work?

    Was just testing it and doesn't make any sense to me..

    PUB Main()|x,y
    
        x:=2
        y:=qexp(x)
        debug(fdec(y))
    
        x:=256
        y:=qlog(x)
        debug(fdec(y))
    
    Cog0  y = 1.401298e-45
    Cog0  y = 2.000000e+00
    

    Getting similar results in PNut, FlexProp, and Spin Tools IDE, so guess that's good anyway...

  • QLOG and QEXP are fixed point

    PUB Main()|x,y
    
        x:=3<<27
        y:=qexp(x)
        debug(udec(y))
    
        x:=256
        y:=qlog(x)>>27
        debug(udec(y))
    
    Cog0  INIT $0000_0000 $0000_0000 load
    Cog0  INIT $0000_0F5C $0000_1850 jump
    Cog0  y = 8
    Cog0  y = 8
    
  • JonnyMacJonnyMac Posts: 9,688

    From the latest Spin2 docs

  • RaymanRayman Posts: 16,072

    Oh, I see .. thanks

  • RaymanRayman Posts: 16,072
    edited 2026-02-24 23:18

    It's a bit confusing as QLOG works in base 2 and log works in e... Think starting to get it now...
    Also have to remember what version of debug type to use... UDEC for qlog, and FDEC for log...

  • JonnyMacJonnyMac Posts: 9,688

    There is a LOG2 operator in that list. Does that match QLOG?

  • @Rayman :

    QLOG is a fixed point logarithm using the cordic. Since it's an interface to P2 hardware it's not available on P1 (similarly for other cordic operations, like ROTXY and POLXY). However, the floating point LOG operators (LOG, LOG2, LOG10) are available on P1 in FlexSpin. On P1 they use the built in log tables in the ROM, so they're a little less accurate than the P2 versions. Ditto for QEXP vs EXP, EXP2, EXP10.

Sign In or Register to comment.