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// <-- CLI SHELL MODE --> 10function [rep]=Fprintf(varargin) 11 fd = mopen(TMPDIR+"/fprintf.rep","w"); 12 varargin(0)=fd; 13 mfprintf(varargin(:)); 14 mclose(fd); 15 fd = mopen(TMPDIR+"/fprintf.rep","r"); 16 str = mgetl(fd); 17 mclose(fd); 18 rep = str; 19endfunction 20function [y]=bugnum(str1,str2,str3) 21 [lhs,rhs] = argn(0); 22 if rhs==3 then 23 y = or(str1<>str2) & or(str1<>str3); 24 else 25 y = or(str1<>str2); 26 end 27endfunction 28// test format "%f" 29// ============================================================================= 30if bugnum(Fprintf("%f",-35),"-35.000000" ) then bugmes();quit;end 31if bugnum(Fprintf("%f",35.55),"35.550000" ) then bugmes();quit;end 32if bugnum(Fprintf("%f",0.00433),"0.004330" , " .004330" ) then bugmes();quit;end 33if bugnum(Fprintf("%f",0.0000000345456),"0.000000" , " .000000" ) then bugmes();quit;end 34if bugnum(Fprintf("%f",1112423453),"1112423453.000000" ) then bugmes();quit;end 35if bugnum(Fprintf("%15f",-35)," -35.000000" ) then bugmes();quit;end 36if bugnum(Fprintf("%15f",0.00433)," 0.004330"," .004330" ) then bugmes();quit;end 37if bugnum(Fprintf("%15f",0.0000000345456)," 0.000000" ," .000000" ) then bugmes();quit;end 38if bugnum(Fprintf("%15f",1112423453),"1112423453.000000" ) then bugmes();quit;end 39if bugnum(Fprintf("%.1f",-35),"-35.0" ) then bugmes();quit;end 40if bugnum(Fprintf("%.0f",-35),"-35" ) then bugmes();quit;end 41if bugnum(Fprintf("%#.0f",-35),"-35." ) then bugmes();quit;end 42if bugnum(Fprintf("%.1f",0.00433),"0.0"," .0") then bugmes();quit;end 43if bugnum(Fprintf("%.15f",0.0000000345456),"0.000000034545600" ," .000000034545600" ) then bugmes();quit;end 44if bugnum(Fprintf("%.1f",11124234534545),"11124234534545.0" ) then bugmes();quit;end 45// test format "%g" 46// ============================================================================= 47if bugnum(Fprintf("%g",-35),"-35" ) then bugmes();quit;end 48if bugnum(Fprintf("%g",35.55),"35.55" ) then bugmes();quit;end 49if bugnum(Fprintf("%g",35.551234567890),"35.5512" ) then bugmes();quit;end 50if bugnum(Fprintf("%+g",35.551234567890),"+35.5512" ) then bugmes();quit;end 51if bugnum(Fprintf("%g",0.00433),"0.00433" ," .00433" ) then bugmes();quit;end 52if bugnum(Fprintf("%g",0.0000000345456),"3.45456e-08","3.45456e-008" ) then bugmes();quit;end 53if bugnum(Fprintf("%g",11124234534545),"1.11242e+13","1.11242e+013" ) then bugmes();quit;end 54if bugnum(Fprintf("%15g",-35)," -35" ) then bugmes();quit;end 55if bugnum(Fprintf("%15g",0.00433)," 0.00433"," .00433" ) then bugmes();quit;end 56if bugnum(Fprintf("%15g",0.0000000345456)," 3.45456e-08"," 3.45456e-008" ) then bugmes();quit;end 57if bugnum(Fprintf("%15g",11124234534545)," 1.11242e+13"," 1.11242e+013" ) then bugmes();quit;end 58if bugnum(Fprintf("%.1g",-35.1),"-4e+01","-4e+001" ) then bugmes();quit;end 59if bugnum(Fprintf("%.0g",-35.1),"-4e+01","-4e+001" ) then bugmes();quit;end 60if bugnum(Fprintf("%#.0g",-35.1),"-4.e+01","-4.e+001" ) then bugmes();quit;end 61if bugnum(Fprintf("%#.0G",-35.1),"-4.E+01","-4.E+001" ) then bugmes();quit;end 62if bugnum(Fprintf("%.1g",0.00433),"0.004" ," .004" ) then bugmes();quit;end 63if bugnum(Fprintf("%.15g",0.0000000345456),"3.45456e-08","3.45456e-008" ) then bugmes();quit;end 64if bugnum(Fprintf("%.1g",11124234534545),"1e+13","1e+013" ) then bugmes();quit;end 65// test format "%e" 66// ============================================================================= 67if bugnum(Fprintf("%e",-35),"-3.500000e+01","-3.500000e+001" ) then bugmes();quit;end 68if bugnum(Fprintf("%e",35.55),"3.555000e+01","3.555000e+001" ) then bugmes();quit;end 69if bugnum(Fprintf("%+e",35.55),"+3.555000e+01","+3.555000e+001" ) then bugmes();quit;end 70if bugnum(Fprintf("%e",35.551234567890),"3.555123e+01","3.555123e+001" ) then bugmes();quit;end 71if bugnum(Fprintf("%e",0.00433),"4.330000e-03","4.330000e-003" ) then bugmes();quit;end 72if bugnum(Fprintf("%e",0.0000000345456),"3.454560e-08","3.454560e-008" ) then bugmes();quit;end 73if bugnum(Fprintf("%e",11124234534545),"1.112423e+13","1.112423e+013" ) then bugmes();quit;end 74if bugnum(Fprintf("%E",11124234534545),"1.112423E+13","1.112423E+013" ) then bugmes();quit;end 75if bugnum(Fprintf("%15e",-35)," -3.500000e+01"," -3.500000e+001" ) then bugmes();quit;end 76if bugnum(Fprintf("%15e",0.00433)," 4.330000e-03"," 4.330000e-003" ) then bugmes();quit;end 77if bugnum(Fprintf("%15e",0.0000000345456)," 3.454560e-08"," 3.454560e-008" ) then bugmes();quit;end 78if bugnum(Fprintf("%+15e",0.0000000345456)," +3.454560e-08"," +3.454560e-008" ) then bugmes();quit;end 79if bugnum(Fprintf("%15e",11124234534545)," 1.112423e+13"," 1.112423e+013" ) then bugmes();quit;end 80if bugnum(Fprintf("%.1e",-35),"-3.5e+01","-3.5e+001" ) then bugmes();quit;end 81if bugnum(Fprintf("%.0e",-35.1),"-4e+01" ,"-4e+001" ) then bugmes();quit;end 82if bugnum(Fprintf("%#.0e",-35.1),"-4.e+01","-4.e+001" ) then bugmes();quit;end 83if bugnum(Fprintf("%.1e",0.00433),"4.3e-03","4.3e-003" ) then bugmes();quit;end 84if bugnum(Fprintf("%.15e",0.0000000345456),"3.454560000000000e-08","3.454560000000000e-008" ) then bugmes();quit;end 85if bugnum(Fprintf("%.1e",11124234534545),"1.1e+13","1.1e+013" ) then bugmes();quit;end 86// test format "%c" 87// ============================================================================= 88if bugnum(Fprintf("%c","t"),"t" ) then bugmes();quit;end 89if bugnum(Fprintf("%10c","t")," t" ) then bugmes();quit;end 90if bugnum(Fprintf("%10.3c","t")," t" ) then bugmes();quit;end 91if bugnum(Fprintf("%-10c","t"),"t " ) then bugmes();quit;end 92// test format "%s" 93// ============================================================================= 94if bugnum(Fprintf("%s","text"),"text" ) then bugmes();quit;end 95if bugnum(Fprintf("%10s","text")," text" ) then bugmes();quit;end 96if bugnum(Fprintf("%10.3s","text")," tex" ) then bugmes();quit;end 97if bugnum(Fprintf("%-10s","text"),"text " ) then bugmes();quit;end 98if bugnum(Fprintf("%s","t"),"t" ) then bugmes();quit;end 99// test format "%x" 100// ============================================================================= 101if bugnum(Fprintf("%x",123),"7b" ) then bugmes();quit;end 102if bugnum(Fprintf("%.10x",123),"000000007b" ) then bugmes();quit;end 103if bugnum(Fprintf("%x",-123),"ffffff85" ) then bugmes();quit;end 104if bugnum(Fprintf("%X",-123),"FFFFFF85" ) then bugmes();quit;end 105if bugnum(Fprintf("%#.3X",12),"0X00C" ) then bugmes();quit;end 106//----------test format %o 107//if bugnum(Fprintf('%015o',-12),'000037777777764' ) then bugmes();quit;end 108//----------test column vector input 109if bugnum(Fprintf("%s\n", ["a";"b"]), ["a";"b"]) then bugmes();quit;end 110