Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "OMBackend"
uuid = "9400bd5f-7561-42f6-8760-03756753da50"
version = "0.5.1"
version = "0.5.2"
authors = ["John Tinnerholm <johti17@liu.se>", "Karim Abdelhak <karim.abdelhak@fh-bielefeld.de>", "AnHeuermann <andreas.heuermann@fh-bielefeld.de>"]

[deps]
Expand Down Expand Up @@ -33,6 +33,7 @@ OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed"
OrdinaryDiffEqBDF = "6ad6398a-0878-4a85-9266-38940aa047c8"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
REPL = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"
SCode = "350d45b0-c210-11e9-3b9e-fdad65bb3d46"
Setfield = "efcf1570-3423-57d1-acb7-fd33fddbac46"
Expand Down
16 changes: 7 additions & 9 deletions src/CodeGeneration/modelicaBuiltins.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
=#

import LinearAlgebra
import Printf
import Symbolics

#= ============================================================================
Expand Down Expand Up @@ -532,16 +533,13 @@ function modelica_String(x::Real, format::AbstractString)
return _cFormat("%" * format, Float64(x))
end

#= C's snprintf of one double, after the width and precision of a `*.*` format. =#
#= C's printf of one double, after the width and precision of a `*.*` format,
through Julia's Printf (the same conversions, as C): Windows exports no
snprintf symbol (the Universal CRT defines it inline), and the ccall failed
there ("could not load symbol", 2026-10-03). =#
function _cFormat(fmt::String, x::Float64; width::Union{Integer, Nothing} = nothing, precision::Integer = 0)
local n = width === nothing ?
@ccall(snprintf(C_NULL::Ptr{UInt8}, 0::Csize_t, fmt::Cstring; x::Cdouble)::Cint) :
@ccall(snprintf(C_NULL::Ptr{UInt8}, 0::Csize_t, fmt::Cstring; Cint(width)::Cint, Cint(precision)::Cint, x::Cdouble)::Cint)
local buf = Vector{UInt8}(undef, n + 1)
width === nothing ?
@ccall(snprintf(buf::Ptr{UInt8}, (n + 1)::Csize_t, fmt::Cstring; x::Cdouble)::Cint) :
@ccall(snprintf(buf::Ptr{UInt8}, (n + 1)::Csize_t, fmt::Cstring; Cint(width)::Cint, Cint(precision)::Cint, x::Cdouble)::Cint)
return String(resize!(buf, n))
width === nothing || (fmt = replace(fmt, "*.*" => string(width, ".", precision)))
return Printf.format(Printf.Format(fmt), x)
end

#= A call of Modelica's String with the arguments the frontend fills in, each
Expand Down
Loading