1// =============================================================================
2// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3// Copyright (C) 2015 - Scilab Enterprises - John GLIKSBERG
4// Copyright (C) ????-2008 - INRIA
5// Copyright (C) ????-2008 - ENPC
6//
7//  This file is distributed under the same license as the Scilab package.
8// =============================================================================
9
10// <-- CLI SHELL MODE -->
11
12function [rep]=Fprintf(varargin)
13    fd = mopen(TMPDIR+"/fprintf.rep","w");
14    varargin(0)=fd;
15    mfprintf(varargin(:));
16    mclose(fd);
17    fd  = mopen(TMPDIR+"/fprintf.rep","r");
18    str = mgetl(fd);
19    mclose(fd);
20    rep = str;
21endfunction
22
23function [y]=bugnum(str1,str2,str3)
24    [lhs,rhs] = argn(0);
25    if rhs==3 then
26        y = or(str1<>str2) & or(str1<>str3);
27    else
28        y = or(str1<>str2);
29    end
30endfunction
31
32// test format "%f"
33// =============================================================================
34
35if bugnum(Fprintf("%f",-35),"-35.000000" ) then pause,end
36if bugnum(Fprintf("%f",35.55),"35.550000" ) then pause,end
37if bugnum(Fprintf("%f",0.00433),"0.004330" , " .004330" ) then pause,end
38if bugnum(Fprintf("%f",0.0000000345456),"0.000000" , " .000000" ) then pause,end
39if bugnum(Fprintf("%f",1112423453),"1112423453.000000" ) then pause,end
40
41if bugnum(Fprintf("%15f",-35),"     -35.000000" ) then pause,end
42if bugnum(Fprintf("%15f",0.00433),"       0.004330","        .004330" ) then pause,end
43if bugnum(Fprintf("%15f",0.0000000345456),"       0.000000" ,"        .000000" ) then pause,end
44if bugnum(Fprintf("%15f",1112423453),"1112423453.000000" ) then pause,end
45
46if bugnum(Fprintf("%.1f",-35),"-35.0" ) then pause,end
47if bugnum(Fprintf("%.0f",-35),"-35" ) then pause,end
48if bugnum(Fprintf("%#.0f",-35),"-35." ) then pause,end
49if bugnum(Fprintf("%.1f",0.00433),"0.0"," .0") then pause,end
50if bugnum(Fprintf("%.15f",0.0000000345456),"0.000000034545600" ," .000000034545600" ) then pause,end
51if bugnum(Fprintf("%.1f",11124234534545),"11124234534545.0" ) then pause,end
52
53// test format "%g"
54// =============================================================================
55
56if bugnum(Fprintf("%g",-35),"-35" ) then pause,end
57if bugnum(Fprintf("%g",35.55),"35.55" ) then pause,end
58if bugnum(Fprintf("%g",35.551234567890),"35.5512" ) then pause,end
59if bugnum(Fprintf("%+g",35.551234567890),"+35.5512" ) then pause,end
60if bugnum(Fprintf("%g",0.00433),"0.00433" ," .00433" ) then pause,end
61if bugnum(Fprintf("%g",0.0000000345456),"3.45456e-08","3.45456e-008" ) then pause,end
62if bugnum(Fprintf("%g",11124234534545),"1.11242e+13","1.11242e+013" ) then pause,end
63
64if bugnum(Fprintf("%15g",-35),"            -35" ) then pause,end
65if bugnum(Fprintf("%15g",0.00433),"        0.00433","         .00433" ) then pause,end
66if bugnum(Fprintf("%15g",0.0000000345456),"    3.45456e-08","   3.45456e-008" ) then pause,end
67if bugnum(Fprintf("%15g",11124234534545),"    1.11242e+13","   1.11242e+013" ) then pause,end
68
69if bugnum(Fprintf("%.1g",-35.1),"-4e+01","-4e+001" ) then pause,end
70if bugnum(Fprintf("%.0g",-35.1),"-4e+01","-4e+001"  ) then pause,end
71if bugnum(Fprintf("%#.0g",-35.1),"-4.e+01","-4.e+001" ) then pause,end
72if bugnum(Fprintf("%#.0G",-35.1),"-4.E+01","-4.E+001" ) then pause,end
73if bugnum(Fprintf("%.1g",0.00433),"0.004" ," .004" ) then pause,end
74if bugnum(Fprintf("%.15g",0.0000000345456),"3.45456e-08","3.45456e-008" ) then pause,end
75if bugnum(Fprintf("%.1g",11124234534545),"1e+13","1e+013" ) then pause,end
76
77// test format "%e"
78// =============================================================================
79
80if bugnum(Fprintf("%e",-35),"-3.500000e+01","-3.500000e+001" ) then pause,end
81if bugnum(Fprintf("%e",35.55),"3.555000e+01","3.555000e+001" ) then pause,end
82if bugnum(Fprintf("%+e",35.55),"+3.555000e+01","+3.555000e+001" ) then pause,end
83if bugnum(Fprintf("%e",35.551234567890),"3.555123e+01","3.555123e+001" ) then pause,end
84if bugnum(Fprintf("%e",0.00433),"4.330000e-03","4.330000e-003" ) then pause,end
85if bugnum(Fprintf("%e",0.0000000345456),"3.454560e-08","3.454560e-008" ) then pause,end
86if bugnum(Fprintf("%e",11124234534545),"1.112423e+13","1.112423e+013" ) then pause,end
87if bugnum(Fprintf("%E",11124234534545),"1.112423E+13","1.112423E+013" ) then pause,end
88
89if bugnum(Fprintf("%15e",-35),"  -3.500000e+01"," -3.500000e+001" ) then pause,end
90if bugnum(Fprintf("%15e",0.00433),"   4.330000e-03","  4.330000e-003" ) then pause,end
91if bugnum(Fprintf("%15e",0.0000000345456),"   3.454560e-08","  3.454560e-008" ) then pause,end
92if bugnum(Fprintf("%+15e",0.0000000345456),"  +3.454560e-08"," +3.454560e-008" ) then pause,end
93if bugnum(Fprintf("%15e",11124234534545),"   1.112423e+13","  1.112423e+013" ) then pause,end
94
95if bugnum(Fprintf("%.1e",-35),"-3.5e+01","-3.5e+001" ) then pause,end
96if bugnum(Fprintf("%.0e",-35.1),"-4e+01" ,"-4e+001" ) then pause,end
97if bugnum(Fprintf("%#.0e",-35.1),"-4.e+01","-4.e+001" ) then pause,end
98if bugnum(Fprintf("%.1e",0.00433),"4.3e-03","4.3e-003" ) then pause,end
99if bugnum(Fprintf("%.15e",0.0000000345456),"3.454560000000000e-08","3.454560000000000e-008" ) then pause,end
100if bugnum(Fprintf("%.1e",11124234534545),"1.1e+13","1.1e+013" ) then pause,end
101
102// test format "%c"
103// =============================================================================
104
105if bugnum(Fprintf("%c","t"),"t" ) then pause,end
106if bugnum(Fprintf("%10c","t"),"         t" ) then pause,end
107if bugnum(Fprintf("%10.3c","t"),"         t" ) then pause,end
108if bugnum(Fprintf("%-10c","t"),"t         " ) then pause,end
109
110// test format "%s"
111// =============================================================================
112if bugnum(Fprintf("%s","text"),"text" ) then pause,end
113if bugnum(Fprintf("%10s","text"),"      text" ) then pause,end
114if bugnum(Fprintf("%10.3s","text"),"       tex" ) then pause,end
115if bugnum(Fprintf("%-10s","text"),"text      " ) then pause,end
116
117if bugnum(Fprintf("%s","t"),"t" ) then pause,end
118
119// test format "%x"
120// =============================================================================
121if bugnum(Fprintf("%x",123),"7b" ) then pause,end
122if bugnum(Fprintf("%.10x",123),"000000007b" ) then pause,end
123if bugnum(Fprintf("%x",-123),"ffffff85" ) then pause,end
124if bugnum(Fprintf("%X",-123),"FFFFFF85" ) then pause,end
125if bugnum(Fprintf("%#.3X",12),"0X00C" ) then pause,end
126
127//----------test format %o
128//if bugnum(Fprintf('%015o',-12),'000037777777764' ) then pause,end
129
130//----------test column vector input
131if bugnum(Fprintf("%s\n", ["a";"b"]), ["a";"b"]) then pause,end
132
133