Skip to content

Unable to Printf floating point integers. #2

Description

@Redrield

I got this library working with printing String literals, but I can't seem to get it to print floating point numbers. Delimiting them with %f leads to 0.000000 no matter the contents of the actual constant, and %d just gives me jibberish nothing close to the actual value.

This is the code that I have

val EXIT_CODE_OK = 0
val STRING_TYPE = Pointer(I8Type)

val module = ModuleBuilder()
val mainFunction = module.createMainFunction()

module.addDeclaration(FunctionDeclaration("printf", I32Type, listOf(STRING_TYPE), varargs = true))

val okBlock = mainFunction.entryBlock()

val num = 2.0
val numConst = FloatConst(num, FloatType)

okBlock.addInstruction(Printf(mainFunction.stringConstForContent("%f\n").reference(), numConst))

okBlock.addInstruction(ReturnInt(EXIT_CODE_OK))
println(module.IRCode())

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions