Skip to content

Inconsistent --strict-math handling of certain properties (hardcoded font etc.) #1627

Closed

Description

@satya61229

Some magic is happening in LESS. I used
ceil(@font-size-base * 1.25);
.. .
...
ceil(@font-size-base * 1.25);

First ceil was working but not the 2nd one. I was working with prepros downloaded recently. I checked in less2css.org there also same result. Now, it is working on less2css.

Another, issue was with this simple line of code:
@font-size-base * 1.25;

This was also used two times in my less. One for tablet and another for desktop with different number. First one was giving calculated number but another one was giving:
0.6em * 1.5; instead of calculated value.

I put the code here using which I was trying ceil and other:

http://stackoverflow.com/questions/19705791/why-this-less-css-is-failing

Also, "1em" with quote was coming whereas expected output was 1em.

Activity

  1. lukeapage commented on Oct 31, 2013

    @lukeapage
    Member

    Sounds like strict maths is on? If it is you have to add parentheses around
    every maths operation or it won't compute.

    If its not that please give more repro steps and exactly what output or
    error you get..
    On 31 Oct 2013 13:44, "Satya Prakash" [email protected] wrote:

    Some magic is happening in LESS. I used
    ceil(@font-size-base * 1.25);

    .. .
    ...
    ceil(@font-size-base * 1.25);

    First ceil was working but not the 2nd one. I was working with prepros
    downloaded recently. I checked in less2css.org there also same result.
    Now, it is working on less2css.

    Another, issue was with this simple line of code:
    @font-size-base * 1.25;

    This was also used two times in my less. One for tablet and another for
    desktop with different number. First one was giving calculated number but
    another one was giving:
    0.6em * 1.5; instead of calculated value.

    I put the code here using which I was trying ceil and other:

    http://stackoverflow.com/questions/19705791/why-this-less-css-is-failing

    Also, "1em" with quote was coming whereas expected output was 1em.

    —
    Reply to this email directly or view it on GitHubhttps://github.com//issues/1627
    .

  2. satya61229 commented on Nov 1, 2013

    @satya61229
    Author

    No, strict math was not on. The Code is still producing same result. The problem was with ceil as well but I have changed to make it work. Below code is not calculating. Here the code is not calculating:

    // Mobile First Approach
    @font-family-base:      "Helvetica Neue", Helvetica, Arial, sans-serif;
    @font-color-base:       #4b4b4b;
    
    @starting-font-size:        0.6em;
    
    @font-size-base:            @starting-font-size;
    @line-height-base:          1;
    @letter-spacing-base:       -0.05em; 
    
    @font-size-medium:          @font-size-base * 1.25;  //ceil(unit(@font-size-base) * 1.25)
    @line-height-medium:        1.2;
    @letter-spacing-medium:     0;
    
    @font-size-large:           @font-size-base * 1.50; //ceil(unit(@font-size-base) * 1.50)
    @line-height-large:         1.5;
    @letter-spacing-large:      0.05em; 
    
    @device-small : 24em;
    @device-medium : 46.8em;
    @device-large : 50em;
    
    
    body{
    font-family: @font-family-base;
    font-size: @font-size-base;
    line-height: @line-height-base;
    color: @font-color-base;
    word-wrap:break-word;
    
    }
    
    @media screen and (max-width:@device-medium) and (min-width: @device-small)
    {
      /* Tablet */
      body {
        font-size:      @font-size-medium;
        line-height:    @line-height-medium;
        letter-spacing: @letter-spacing-medium;
      }
    }
    @media screen and (min-width: @device-large)
    {
      /* Large screen */
      body {
        font:           @font-size-large;
        line-height:    @line-height-large;
        letter-spacing: @letter-spacing-large;
      }
    }
    

    Output in last media query:

    @media screen and (min-width: 50em) {
      /* Large screen */
      body {
        font: 0.6em * 1.5;
        line-height: 1.5;
        letter-spacing: 0.05em;
      }
    }
    

    Just checked in less2css.org. Above output is coming there as well w/o strict math.

  3. seven-phases-max commented on Nov 3, 2013

    @seven-phases-max
    Member

    @satya61229, see my answer here.
    @lukeapage, it's in tree/rule.js:34.

  4. satya61229 commented on Nov 4, 2013

    @satya61229
    Author

    Got it. It can be the case. Checked again in less2css.org and it work when changed to font-size from font. Accepted as right answer there. Thanks.

  5. scottgit commented on Nov 5, 2013

    @scottgit

    @lukeapage I know satya61229 closed his own issue here, but I'm not sure that the "issue" is actually resolved. The fact that a function like ceil() would not do its math correctly because it was being called in a font: property when strict-math was off seems like a bug to me. I understand that the font property has the special case of needing to ignore the size/line-height syntax for math purposes, but that definitely should not affect maths inside functions, and is even questionable if it should affect any math outside a function except perhaps a division. To me, these should both resolve to 240px if strict-math is off:

     font: 12px * 20px;
     font-size: 12px * 20px;
    

    I have not looked to see what other discussions you have had about font and the use of the size/line-height syntax, but I could even see spaces being important with strict-math off, so that:

     font: 12px/20px; // no math done in the font property
     font: 12px / 20px; // math done even in font property
    

    However, that might be pushing it. Of course, all the above would require parenthesis if strict-math was on, no matter the operation or if it was in a function call like ceil().

  6. satya61229 commented on Nov 5, 2013

    @satya61229
    Author

    For my purpose, working with LESS, it is resolved as I found a way to work. but from LESS own stability I agree with @scottgit . So, I am opening it. Hope you can close it later.

  7. lukeapage commented on Nov 16, 2013

    @lukeapage
    Member

    You are right, we switch on the option inside font declarationa but we should actually switch it off again for functions.

  8. changed the title [-]There is some issue with ceil() and math calculation[/-] [+]Inconsistent `--strict-math` handling of certain properties (hardcoded `font` etc.)[/+] on Apr 17, 2016
  9. seven-phases-max commented on Apr 17, 2016

    @seven-phases-max
    Member

    Merging to #1880 (since this one is impossible to "fix" w/o breaking a lot of things anyway).

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions