On Sun, Apr 14, 2024 at 11:00:33AM +0200, Grégory Vanuxem wrote:
> Le sam. 13 avr. 2024 à 21:05, Waldek Hebisch <[email protected]> a écrit :
> >
> > On Sun, Apr 07, 2024 at 06:05:39AM +0200, Grégory Vanuxem wrote:
> > >
> > > It is possible to modify some parameters to Float output routines,
> > > what about returning the previous settings? For example
> > > outputSpacing(n) returns Void but if you want to temporarily modify
> > > this setting, in Spad for example, reverting to the user setting is
> > > not possible.
<snip>
> > Thinking more about this: it should be possible to restore _whole_
> > previous settings.
<snip>
> > that we need funtion
> >
> >    set_output_mode : (Stiring, Integer) -> Record(mode : String, prec : 
> > String)
<snip>
> > which sets desired mode.  I wrote above version that returns old settings,
> > but in principle version that returns Void is enough given 
> > 'get_output_mode'.
> 
> Agreed.

Attached is possible patch.

-- 
                              Waldek Hebisch

-- 
You received this message because you are subscribed to the Google Groups 
"FriCAS - computer algebra system" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/fricas-devel/ZivczlB2vr6-HPAJ%40fricas.org.
diff --git a/src/algebra/float.spad b/src/algebra/float.spad
index 9eb4c7a..fc8385c 100644
--- a/src/algebra/float.spad
+++ b/src/algebra/float.spad
@@ -129,9 +129,14 @@ Float():
    outputGeneral : N -> Void
       ++ outputGeneral(n) sets the output mode to general notation
       ++ with n significant digits displayed.
-   outputSpacing : N -> Void
+   outputSpacing : N -> N
       ++ outputSpacing(n) inserts a space after n (default 10) digits on output;
       ++ outputSpacing(0) means no spaces are inserted.
+      ++ Returns old setting.
+   get_output_mode : () -> Record(mode : String, prec : Integer)
+      ++ get_output_mode() returns current output mode and precision
+   set_output_mode : (String, Integer) -> Void
+      ++ set_output_mode(mode, precision) sets output mode and precision.
   == add
    BASE ==> 2
    BITS : PI := 68 -- 20 digits
@@ -905,7 +910,11 @@ Float():
          s := if zero? SPACING then "E" else " E "
          concat ["0.", t, s, convert(e+n)@S]
 
-   outputSpacing n == SPACING := n
+   outputSpacing n ==
+       old_val := SPACING
+       SPACING := n
+       old_val
+
    outputFixed() == (OUTMODE := "fixed"; OUTPREC := -1)
    outputFixed n == (OUTMODE := "fixed"; OUTPREC := n::I)
    outputGeneral() == (OUTMODE := "general"; OUTPREC := -1)
@@ -913,6 +922,19 @@ Float():
    outputFloating() == (OUTMODE := "floating"; OUTPREC := -1)
    outputFloating n == (OUTMODE := "floating"; OUTPREC := n::I)
 
+   get_output_mode() : Record(mode : String, prec : Integer) ==
+       [OUTMODE, OUTPREC]
+
+   valid_modes : List(String) := ["fixed", "general", "floating"]
+
+   set_output_mode(mode : String, prec : Integer) : Void ==
+       prec < 0 and prec ~= -1 =>
+           error "set_output_mode: invalid precision"
+       not(member?(mode, valid_modes)) =>
+           error "set_output_mode: invalid mode"
+       OUTMODE := mode
+       OUTPREC := prec
+
    convert(f) : S ==
       b : Integer :=
         OUTPREC = -1 and not zero? f =>

Reply via email to